How to prevent “aspxerrorpath” being passed as a query string to ASP.NET custom error pages

后端 未结 11 860
夕颜
夕颜 2020-12-29 03:36

In my ASP.NET web application, I have defined custom error pages in my web.config file as follows:



        
11条回答
  •  独厮守ぢ
    2020-12-29 03:51

    In the global.asax, catch the 404 error and redirect to the file not found page. I didn't require the aspxerrorpath and it worked a treat for me.

    void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError();
        if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
        {
            Response.Redirect("~/filenotfound.aspx");
        }
        else
        {
            // your global error handling here!
        }
    }
    

提交回复
热议问题