Passing long querystrings over urls shows page not found error(404)

[亡魂溺海] 提交于 2019-12-24 14:05:36

问题


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);

    }

回答1:


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();


来源:https://stackoverflow.com/questions/27758681/passing-long-querystrings-over-urls-shows-page-not-found-error404

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!