Skip to content

Instantly share code, notes, and snippets.

@odenijs
Created June 27, 2013 11:50
Show Gist options
  • Save odenijs/5875865 to your computer and use it in GitHub Desktop.
Save odenijs/5875865 to your computer and use it in GitHub Desktop.
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment