odenijs
6/27/2013 - 11:50 AM

Global asax 404 redirect on application error to skip 302 status first. http://stackoverflow.com/questions/667053/best-way-to-implement-a-40

Global asax 404 redirect on application error to skip 302 status first. http://stackoverflow.com/questions/667053/best-way-to-implement-a-404-in-asp-net

protected void Application_Error(object sender, EventArgs e)
{
    //Application.Lock();
    //Application["LastException"] = Server.GetLastError();

    var serverError = Server.GetLastError() as HttpException;

    if (serverError != null)
    {
        int errorCode = serverError.GetHttpCode();

        if (404 == errorCode)
        {
            Server.ClearError();
            Server.Transfer("/error.aspx");
        }
    }

    //Application.UnLock();
}