473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

System.Web.HttpException / 404 Not Found

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
2 6288

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Amy | last post by:
Hi, I'm suddenly getting this error when I post back from my application. the application worked once, i added some code on one page (customizing a datagrid), and suddenly I'm getting this...
0
by: Steve | last post by:
Hi All, I keep getting the "System.Web.HttpException: Request timed out." error message when I was uploading image files (about 400 image files) to SQL table, all those image files are FTP to...
3
by: Gvnn | last post by:
Hi, I've a little problem, i've an asp.net page, with a runat server form, like this: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb" Inherits="indexGstPro"%> <HTML>...
2
by: Nicolas LeBlanc | last post by:
I've seen several message on newsgroup, but none helped me fixed this damned problem. I am not on a load balancing, and the copy in the server is there for ages, and yet I receive 10 to 20 times...
0
by: Jack Wright | last post by:
Dear All, I have a web Application "http://localhost/Web/WebForm1.aspx" that calls a WebService from "http://localhost/webserviceapp/service1.asmx"...I have set the executionTimeout to 10 secs in...
5
by: Jack Wright | last post by:
Dear All, I have a web Application "http://localhost/Web/WebForm1.aspx" that calls a WebService from "http://localhost/webserviceapp/service1.asmx"...I have set the executionTimeout to 10 secs in...
0
by: Frank | last post by:
Does anyone have any clues as to what might have caused this error? Only the startup web page uses ASP compatibility mode. I've tested this thru 100000s of cycles, and this recently appears in one...
1
by: dima | last post by:
Hi All, I know some of you had this problem in production. Did anyone find out how to fix this problem or what is the cause of it? System.Web.HttpException: Invalid_Viewstate ...
5
by: dpomt | last post by:
I have overwritten Application_Error in my GlobalAsax to handle errors. From time to time, I am getting exceptions I have never seen before (see below). What do this exceptions mean? Why are...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.