Getting URL that caused 404 error

  • Thread starter Greg Collins [Microsoft MVP]
  • Start date
G

Greg Collins [Microsoft MVP]

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)?
 
K

Ken Schaefer

Isn't the original URL appended in the querystring?

Cheers
Ken


"Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_com> wrote in message
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)?
 
G

Greg Collins [Microsoft MVP]

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).
 
K

Ken Schaefer

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
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).
 
G

Greg Collins [Microsoft MVP]

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.
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

Greg said:
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 in IIS's custom 404 error handling


Kirit
 
G

Greg Collins [Microsoft MVP]

So is the question mark character the only character I need to be worried about?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top