Google Answers Logo
View Question
 
Q: Throwing ASP.NET's 404 error message (framework 1.0/1.1) ( No Answer,   3 Comments )
Question  
Subject: Throwing ASP.NET's 404 error message (framework 1.0/1.1)
Category: Computers > Programming
Asked by: joelnet-ga
List Price: $10.00
Posted: 21 Dec 2004 16:07 PST
Expires: 03 Feb 2005 19:22 PST
Question ID: 445749
I've created an http handler and have a condition that requires I
throw a 404 message.  I want to use ASP.NET's 404 message, just incase
there is a custom 404 in the web.config I would like ASP.NET to handle
the 404.  So if there is no custom 404, it will be the basic IIS 404
page.  And if there is a custom 404 in the web.config, it will
redirect to that page.

I tried asking this question on asp.net's forums, but didn't like the
answer I received... here is the link
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=762031

I need it to satisfy both conditions (custom 404 and non custom 404). 
Ideally, the functionality I want would be if I could set a flag to
ignore the request, but there doesn't seem to be one in IHttpHandler. 
So now I'm looking for another way.

Request for Question Clarification by mathtalk-ga on 22 Dec 2004 05:36 PST
Hi, joelnet-ga:

Are you trying to "trap" handling of all 404 errors in an IIS
instance, or only those associated with requests for ASPX pages?

regards, mathtalk-ga

Clarification of Question by joelnet-ga on 22 Dec 2004 13:42 PST
no, please read original post.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Throwing ASP.NET's 404 error message (framework 1.0/1.1)
From: captainclaw-ga on 03 Jan 2005 05:18 PST
 
Reponse object is having a StatusCode property which is the HTTP error code itself.

So instead of redirecting the page using Response.Redirect()

Set the response error code as 404 and set the Error message also.
the code would be somewhat similar to : 

If ( your condition to check whether you need redirection) Then
Response.StatusCode = 404
Response.StatusDescription ="File Not found"

End If
Subject: Re: Throwing ASP.NET's 404 error message (framework 1.0/1.1)
From: captainclaw-ga on 03 Jan 2005 05:20 PST
 
note that Response.Redirect will stop processing the remainging code
in the page while this code snippet will not do that. So you need to
make sure that the remaining code is not processed by putting those
lines in the Else part of the condition.

There may be another way for doing this.. But I did it this way when
there was a need for this in one of my projects.
Subject: Re: Throwing ASP.NET's 404 error message (framework 1.0/1.1)
From: joelnet-ga on 03 Jan 2005 15:22 PST
 
Ok, I believe the true answer is "it is not possible".

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy