I am catching unhandled errors using the Application_Error
method within my Global.asax
file, this is what I have so far:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if(httpException != null)
{
string action;
switch(httpException.GetHttpCode())
{
case 404:
action = "404";
break;
case 500:
action = "500";
break;
default:
action = "Other";
break;
}
Server.ClearError();
Response.Redirect(String.Format("~/Error/?error=" + action + "&message=" + exception.Message));
}
}
However I really don't like the idea of redirecting the user to error page, infact I would like the URL to remain the same.
For example when a page doesn't exist it shouldn't redirect to the path in the URL, instead it should remain on the same page but still display an error.
Does anyone know how to do this?