protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
bool isAjaxRequest = Context.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
if (!isAjaxRequest)
{
if (exception is HttpException httpException)
{
int httpCode = httpException.GetHttpCode();
if (httpCode == 404)
{
Response.Redirect("~/Error/NotFound");
}
else if (httpCode == 500)
{
Response.Redirect("~/Error/ServerError");
}
else
{
Response.Redirect("~/Error/Error");
}
}
else
{
Response.Redirect("~/Error/Error");
}
}
}