By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,330 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,330 IT Pros & Developers. It's quick & easy.

System.Web.HttpException / 404 Not Found

P: n/a
Zeb
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

Jan 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Here's a snippet rom our Global.asax which accomplishes the same
thing:
if ( ex is HttpException &&
ex.InnerException is FileNotFoundException &&
!File.Exists(Request.PhysicalPath))
HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On 24 Jan 2007 11:23:23 -0800, "Zeb" <m.*******@gmail.comwrote:

>
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
Jan 24 '07 #2

P: n/a
Zeb
Brilliant - that's perfect, thanks :)

On 24 Jan, 19:42, Samuel R. Neff <samueln...@nomail.comwrote:
Here's a snippet rom our Global.asax which accomplishes the same
thing:

if ( ex is HttpException &&
ex.InnerException is FileNotFoundException &&
!File.Exists(Request.PhysicalPath))

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On 24 Jan 2007 11:23:23 -0800, "Zeb" <m.winw...@gmail.comwrote:


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- Hide quoted text -- Show quoted text -
Jan 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.