通过 url 传递长查询字符串显示页面未找到错误 (404) [英] Passing long querystrings over urls shows page not found error(404)

查看:40
本文介绍了通过 url 传递长查询字符串显示页面未找到错误 (404)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个error.aspx"页面,如果发现任何异常,它会向我发送邮件.当我手动打开页面 mysite.com/error.aspx 时,页面打开正常,但是当它被带有 exception.message 和 exception.stackTrace 作为查询字符串的 catch 块重定向时,我收到错误找不到页面".查询字符串是否指示浏览器打开不同的 url?不过,它在本地主机上运行时运行良好.

I have a "error.aspx" page which is there to mail me if any exception is caught. When I open the page manually, mysite.com/error.aspx, the page opens fine but when it is redirected by a catch block with the exception.message and exception.stackTrace as querystrings, I get an error "page not found". Are the querystrings directing the browser to open a different url? It works fine when run on localhost, though.

     public void send_error(Exception ex)
    {
   Response.Redirect("error.aspx?time=" + DateTime.Now.ToString() + "&ex=" + ex.Message + "&st=" + ex.StackTrace.Replace("\n", " "), false);

    }

推荐答案

如果你检查这个 文章,你会看到 url 字符串的最大查询长度为 Internet Explorer 的 2048 个符号.可能 url 更大,因此你有这个问题.一种解决方案是将会话中的期望消息保存为字符串,然后在其他页面上检索它.

If you check this Article, you will see that the max query length of url string is 2048 symbols for Internet explorer. Probably the url is bigger and because of that you have this problem. One solution is to save the desire message in the session as string and after that retrieve it on other pages.

string errorMessage = DateTime.Now.ToString() + " " + ex.Message + " " + ex.StackTrace.Replace("\n", " ");
Session["__ErrMessage"] = errorMessage;

当你在其他页面时,你可以像这样访问这个字符串:

When you are in other pages you can access this string like this:

string errMessage = "";

if(Session["__ErrMessage"] != null)
    errMessage = Session["ErrMessage"].ToString();

这篇关于通过 url 传递长查询字符串显示页面未找到错误 (404)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆