Quick question!
I'm using Global.aspx in my web app to catch unhandled exceptions, log
them and redirect the user to a "something went wrong" page.
This means that at the moment, if the user visits a page that doesn't
exist, they're taken to the generic error page ... but I'd much rather
let them know that the page wasn't found and that they might like to
double check the url.
This is the code I currently have in my Glocal.aspx file:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
if (Context.Error.ToString() != "Thread was being aborted")
{
try
{
MembershipUser user = Membership.GetUser();
int iUserID = 0;
if (user != null)
iUserID = (int)user.ProviderUserKey;
ErrorsBLL errors = new ErrorsBLL();
errors.AddError(Context.Error.ToString(),
Request.ServerVariables["SCRIPT_NAME"], iUserID);
}
finally
{
string root = Config.Root(true);
if (Context.Error is System.Web.HttpException)
Response.Redirect(root + "FileNotFound.aspx");
else
Response.Redirect(root + "Error.aspx");
}
}
}
As you can see, I'm capturing System.Web.HttpExceptions ... but this
isn't ideal because it's not specific to a 404 - so is there any way to
capture a 404 specifically???
Many Thanks,
Matt