Skip to content

Instantly share code, notes, and snippets.

@KevM
Created January 12, 2011 20:28
Show Gist options
  • Select an option

  • Save KevM/776816 to your computer and use it in GitHub Desktop.

Select an option

Save KevM/776816 to your computer and use it in GitHub Desktop.
public class Global : HttpApplication
{
protected void Application_OnError()
{
if (Context.IsCustomErrorEnabled && isAjaxRequest())
{
// By default, customErrors will cause a 302 redirect
// We really want a 500 response, so that the client request knows there was an error
error_without_redirect();
}
}
private void error_without_redirect()
{
Server.ClearError();
Response.ClearContent();
Response.StatusCode = 500;
Response.StatusDescription = "Internal Server Error";
Response.Write("<html><body><h1>500 Internal Server Error</h1></body></html>");
}
private static bool isAjaxRequest()
{
return HttpContext.Current.IsAjaxRequest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment