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

Getting URL that caused 404 error

P: n/a
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 )
Oct 3 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Isn't the original URL appended in the querystring?

Cheers
Ken
"Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_comwrote in message
news:Ok**************@TK2MSFTNGP03.phx.gbl...
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 )

Oct 3 '06 #2

P: n/a
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 )
Oct 3 '06 #3

P: n/a
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_comwrote in message
news:e1**************@TK2MSFTNGP04.phx.gbl...
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 )

Oct 4 '06 #4

P: n/a
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 )
Oct 5 '06 #5

P: n/a

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

Oct 6 '06 #6

P: n/a
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 )
Oct 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.