Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting URL that caused 404 error

Reply
Thread Tools

Getting URL that caused 404 error

 
 
Greg Collins [Microsoft MVP]
Guest
Posts: n/a
 
      10-03-2006
If I go into IIS and change the default 404 error page to an ASPX page, is there any way to then identify the url that was typed in that caused the custom 404 page to be loaded? If so, how do I do that (C# prefered)?

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )


 
Reply With Quote
 
 
 
 
Ken Schaefer
Guest
Posts: n/a
 
      10-03-2006
Isn't the original URL appended in the querystring?

Cheers
Ken


"Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_com> wrote in message
news:(E-Mail Removed)...
If I go into IIS and change the default 404 error page to an ASPX page, is
there any way to then identify the url that was typed in that caused the
custom 404 page to be loaded? If so, how do I do that (C# prefered)?

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )



 
Reply With Quote
 
 
 
 
Greg Collins [Microsoft MVP]
Guest
Posts: n/a
 
      10-03-2006
If you are using the web.config error redirecting, you get a partial url listed in the query string under aspxerrorpath=/path (except that if in this case all the original query string parameters are lopped off and you only get the path to the page -- not as useful as it could be).

In my case, I'm referring to going into the IIS settings and modifying the pointer to the default 404 error page to a custom page. In this case the browser address well still shows the address that cased the 404 error (as it was typed in or navigated to), but the custom 404 page displays. No modification is made to the url.

It is in this latter case that I want to be able to identify the url in the address well that was sent to my custom 404 page (again this is from an IIS modification, not a web.config setting).

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )


 
Reply With Quote
 
Ken Schaefer
Guest
Posts: n/a
 
      10-04-2006
Hi,

Check both the Querystring and the current page name. Depending on whether
the file was handler by the IIS Static File Handler, or handled by an ISAPI
filter, you will see different results in the browser's address bar. This is
a function of whether IIS is internally using something akin to
Server.Execute to transfer across to the 404 page, or is using something
akin to Response.Redirect() to transfer across to the 404 page.

Cheers
Ken


"Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_com> wrote in message
news:(E-Mail Removed)...
If you are using the web.config error redirecting, you get a partial url
listed in the query string under aspxerrorpath=/path (except that if in this
case all the original query string parameters are lopped off and you only
get the path to the page -- not as useful as it could be).

In my case, I'm referring to going into the IIS settings and modifying the
pointer to the default 404 error page to a custom page. In this case the
browser address well still shows the address that cased the 404 error (as it
was typed in or navigated to), but the custom 404 page displays. No
modification is made to the url.

It is in this latter case that I want to be able to identify the url in the
address well that was sent to my custom 404 page (again this is from an IIS
modification, not a web.config setting).

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )



 
Reply With Quote
 
Greg Collins [Microsoft MVP]
Guest
Posts: n/a
 
      10-05-2006
Interesting. . . you are right on that. Even though you don't see a query string, there's one there in the format of:

404;http://localhost:80/path_you_typed

This query string is encoded--so it must be decoded first to be useful. I also note that it added the port ":80" to the host name.

But this is sufficient to get me what I need.

Thanks.

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )


 
Reply With Quote
 
=?iso-8859-1?q?Kirit_S=E6lensminde?=
Guest
Posts: n/a
 
      10-06-2006

Greg Collins [Microsoft MVP] wrote:
> Interesting. . . you are right on that. Even though you don't see a query string, there's one there in the format of:
>
> 404;http://localhost:80/path_you_typed
>
> This query string is encoded--so it must be decoded first to be useful. I also note that it added the port ":80" to the host name.
>
> But this is sufficient to get me what I need.


You need to be a little careful with how you interpret the string. If
the URL is all plain ASCII characters then it should be sufficient, but
there are some edge conditions that may be relevant:

http://www.kirit.com/Errors%20in%20I...ror%20handling


Kirit

 
Reply With Quote
 
Greg Collins [Microsoft MVP]
Guest
Posts: n/a
 
      10-07-2006
So is the question mark character the only character I need to be worried about?
Thanks.

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
How to tell if Application_Error is caused by HTTP error 404? Edward ASP .Net 2 11-06-2008 04:40 PM
Intercept IIS 404 errors? Issue with Viewstate and 404 Jonathan Folland ASP .Net 2 03-17-2005 02:32 AM
Getting the original URL in a custom 404 error page/servlet (Tomcat) Anders Skar Java 1 07-22-2004 07:12 PM
url rewriting giving 404 error when host site with windows 2003 server and iis6.0 sandeep pandit via .NET 247 ASP .Net 0 04-28-2004 10:54 AM



Advertisments