Getting URL that caused 404 error

Discussion in 'ASP .Net' started by Greg Collins [Microsoft MVP], Oct 3, 2006.

  1. 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 )
    Greg Collins [Microsoft MVP], Oct 3, 2006
    #1
    1. Advertising

  2. Greg Collins [Microsoft MVP]

    Ken Schaefer Guest

    Isn't the original URL appended in the querystring?

    Cheers
    Ken


    "Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_com> wrote in message
    news:...
    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 )
    Ken Schaefer, Oct 3, 2006
    #2
    1. Advertising

  3. 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 )
    Greg Collins [Microsoft MVP], Oct 3, 2006
    #3
  4. Greg Collins [Microsoft MVP]

    Ken Schaefer Guest

    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:...
    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 )
    Ken Schaefer, Oct 4, 2006
    #4
  5. 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 )
    Greg Collins [Microsoft MVP], Oct 5, 2006
    #5
  6. 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 in IIS's custom 404 error handling


    Kirit
    =?iso-8859-1?q?Kirit_S=E6lensminde?=, Oct 6, 2006
    #6
  7. 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 )
    Greg Collins [Microsoft MVP], Oct 7, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. henry
    Replies:
    1
    Views:
    387
    =?Utf-8?B?RGF2aWQgQ29lLCBNQ1A=?=
    Feb 23, 2004
  2. Jonathan Folland
    Replies:
    2
    Views:
    1,614
    Jonathan Folland
    Mar 17, 2005
  3. Anders Skar
    Replies:
    1
    Views:
    2,086
    Anders Skar
    Jul 22, 2004
  4. =?Utf-8?B?QW5kcmV3IEhheWVz?=

    Getting Rid Of Validation Warning Caused By Title Attribute In Web

    =?Utf-8?B?QW5kcmV3IEhheWVz?=, Jun 28, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    342
    =?Utf-8?B?QW5kcmV3IEhheWVz?=
    Jun 28, 2007
  5. Edward
    Replies:
    2
    Views:
    531
    Edward
    Nov 6, 2008
Loading...

Share This Page