Pulling the querystring off a 404 redirect

Discussion in 'ASP General' started by Scott McNair, Apr 12, 2004.

  1. Scott McNair

    Scott McNair Guest

    Hi,

    We've got a custom 404 error page set up that attempts to mine information
    such as the page that generated the error, the querystring they used, the
    date/time, etc.

    However, we're running into a problem on the querystring portion... the
    querystring is being replaced with the error #, a semicolon, and the
    calling page. For example, if our 404 page was called error.asp, the bad
    request [http://mysite.com/badpage.asp?query=string] would turn into
    [http://mysite.com/error.asp?404;badpage.asp].

    Is there a way I can get the lost querystring back?

    Thanks,
    Scott
    Scott McNair, Apr 12, 2004
    #1
    1. Advertising

  2. Scott McNair

    Ray at Guest

    I believe this should get you the URL with or without any querystring:

    custom404.asp:
    <%
    RESPONSE.WRITE "You tried to go to " & LCase(Replace(Request.Querystring,
    "404;", ""))
    RESPONSE.END
    %>

    Ray at work




    "Scott McNair" <> wrote in message
    news:Xns94C989A98562Csfmco@207.46.248.16...
    > Hi,
    >
    > We've got a custom 404 error page set up that attempts to mine information
    > such as the page that generated the error, the querystring they used, the
    > date/time, etc.
    >
    > However, we're running into a problem on the querystring portion... the
    > querystring is being replaced with the error #, a semicolon, and the
    > calling page. For example, if our 404 page was called error.asp, the bad
    > request [http://mysite.com/badpage.asp?query=string] would turn into
    > [http://mysite.com/error.asp?404;badpage.asp].
    >
    > Is there a way I can get the lost querystring back?
    >
    > Thanks,
    > Scott
    Ray at, Apr 12, 2004
    #2
    1. Advertising

  3. Scott McNair

    Scott McNair Guest

    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    news::

    > I believe this should get you the URL with or without any querystring:
    >
    > custom404.asp:
    > <%
    > RESPONSE.WRITE "You tried to go to " & LCase(Replace

    (Request.Querystring,
    > "404;", ""))
    > RESPONSE.END
    > %>


    Thanks, Ray... no help though. I'm not looking for the original URL;
    I'm looking for the querystring. I'm getting the error and the original
    page just fine by doing a split on the semicolon. The querystring
    however seems to just disappear. I even did:

    For Each Item In Request.ServerVariables
    Response.Write Item & ": " & Request.ServerVariables(Item) & "<br>
    <br>"
    Next

    in hopes that it would be hidden in some server variable somewhere, but
    no luck.
    Scott McNair, Apr 12, 2004
    #3
  4. Scott McNair

    Scott McNair Guest

    Scott McNair, Apr 12, 2004
    #4
  5. Scott McNair

    Ray at Guest

    Dim sUrlRequested, iQSpot, sQString
    sUrlRequested = LCase(Replace(Request.Querystring,"404;", ""))
    iQSpot = Instr(sUrlRequested, "?")
    If iQSpot > 0 Then
    sQString = Right(sUrlRequested, Len(sUrlRequested) - iQSpot)
    End If
    Response.Write sQString

    Ray at work


    "Scott McNair" <> wrote in message
    news:Xns94C98DF88EF85sfmco@207.46.248.16...
    > "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    > news::
    >
    > > I believe this should get you the URL with or without any querystring:
    > >
    > > custom404.asp:
    > > <%
    > > RESPONSE.WRITE "You tried to go to " & LCase(Replace

    > (Request.Querystring,
    > > "404;", ""))
    > > RESPONSE.END
    > > %>

    >
    > Thanks, Ray... no help though. I'm not looking for the original URL;
    > I'm looking for the querystring. I'm getting the error and the original
    > page just fine by doing a split on the semicolon. The querystring
    > however seems to just disappear. I even did:
    >
    > For Each Item In Request.ServerVariables
    > Response.Write Item & ": " & Request.ServerVariables(Item) & "<br>
    > <br>"
    > Next
    >
    > in hopes that it would be hidden in some server variable somewhere, but
    > no luck.
    Ray at, Apr 12, 2004
    #5
  6. Scott McNair

    Scott McNair Guest

    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    news:#:

    > Dim sUrlRequested, iQSpot, sQString
    > sUrlRequested = LCase(Replace(Request.Querystring,"404;", ""))
    > iQSpot = Instr(sUrlRequested, "?")
    > If iQSpot > 0 Then
    > sQString = Right(sUrlRequested, Len(sUrlRequested) - iQSpot)
    > End If
    > Response.Write sQString


    Thanks Ray,

    Unfortunately it still doesn't work, since the querystring is getting
    lost when it's getting redirected to the asp page, at least on my box.

    Here's an example of code I was using before, and what it returns for
    the page I went to [http://localhost/blah.asp?abc=123]:

    The error # is <%=Split(Request.ServerVariables("QUERY_STRING"),";")
    (0)%><br>
    The bad page is <%=Split(Request.ServerVariables("QUERY_STRING"),";")
    (1)%><br>

    It returns the following:

    The error # is 404
    The bad page is http://localhost/blah.asp

    The address it shows in the address bar is
    [http://localhost/Errors/Error.asp?404;http://localhost/blah.asp].

    I tried running your code, and it returns nothing (since the querystring
    is being stripped on forwarding).

    Thanks,
    Scott
    Scott McNair, Apr 12, 2004
    #6
  7. Scott McNair

    Evertjan. Guest

    Ray at <%=sLocation%> [MVP] wrote on 12 apr 2004 in
    microsoft.public.inetserver.asp.general:
    > Dim sUrlRequested, iQSpot, sQString
    > sUrlRequested = LCase(Replace(Request.Querystring,"404;", ""))
    > iQSpot = Instr(sUrlRequested, "?")
    > If iQSpot > 0 Then
    > sQString = Right(sUrlRequested, Len(sUrlRequested) - iQSpot)
    > End If
    > Response.Write sQString



    r = split(Request.Querystring,"?")
    sQString = ""
    if ubound(r)>0 then sQString = r(1)
    Response.Write sQString


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Apr 12, 2004
    #7
  8. Scott McNair

    Ray at Guest

    I'm sorry. When I was testing here, I was not going to
    http://site/page.asp?x=d. I was going to something more like:
    http://site/dir/?kjd=kjdf

    When you go to a non-existent page, you see the 404 url in the browser. For
    a non-existant directory, the URL does not change. Why? I guess because
    this is what someone decided when creating IIS or IE or something! I can't
    find any way to carry the querystring over as you've been trying to do...

    Ray at work





    "Scott McNair" <> wrote in message
    news:Xns94C994DF87B95sfmco@207.46.248.16...

    > Thanks Ray,
    >
    > Unfortunately it still doesn't work, since the querystring is getting
    > lost when it's getting redirected to the asp page, at least on my box.
    >
    > Here's an example of code I was using before, and what it returns for
    > the page I went to [http://localhost/blah.asp?abc=123]:
    >
    > The error # is <%=Split(Request.ServerVariables("QUERY_STRING"),";")
    > (0)%><br>
    > The bad page is <%=Split(Request.ServerVariables("QUERY_STRING"),";")
    > (1)%><br>
    >
    > It returns the following:
    >
    > The error # is 404
    > The bad page is http://localhost/blah.asp
    >
    > The address it shows in the address bar is
    > [http://localhost/Errors/Error.asp?404;http://localhost/blah.asp].
    >
    > I tried running your code, and it returns nothing (since the querystring
    > is being stripped on forwarding).
    >
    > Thanks,
    > Scott
    Ray at, Apr 12, 2004
    #8
  9. Scott McNair

    Scott McNair Guest

    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    news::

    > I'm sorry. When I was testing here, I was not going to
    > http://site/page.asp?x=d. I was going to something more like:
    > http://site/dir/?kjd=kjdf
    >
    > When you go to a non-existent page, you see the 404 url in the
    > browser. For a non-existant directory, the URL does not change. Why?
    > I guess because this is what someone decided when creating IIS or IE
    > or something! I can't find any way to carry the querystring over as
    > you've been trying to do...


    Thanks, Ray! At least I know I'm not going crazy. ;-)

    -Scott
    Scott McNair, Apr 12, 2004
    #9
  10. Scott McNair

    Ray at Guest

    I'm beginning to suspect that the behavior is different in IIS6 in WS2003.
    Unfortunately, where I am, the only WS2003 servers don't have IIS on them,
    and I can't install it. I think I'll have to install 2003 on my intranet
    server tomorrow. ;]

    Ray at work

    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:...
    > I'm sorry. When I was testing here, I was not going to
    > http://site/page.asp?x=d. I was going to something more like:
    > http://site/dir/?kjd=kjdf
    >
    > When you go to a non-existent page, you see the 404 url in the browser.

    For
    > a non-existant directory, the URL does not change. Why? I guess because
    > this is what someone decided when creating IIS or IE or something! I

    can't
    > find any way to carry the querystring over as you've been trying to do...
    >
    > Ray at work
    >
    >
    >
    >
    >
    > "Scott McNair" <> wrote in message
    > news:Xns94C994DF87B95sfmco@207.46.248.16...
    >
    > > Thanks Ray,
    > >
    > > Unfortunately it still doesn't work, since the querystring is getting
    > > lost when it's getting redirected to the asp page, at least on my box.
    > >
    > > Here's an example of code I was using before, and what it returns for
    > > the page I went to [http://localhost/blah.asp?abc=123]:
    > >
    > > The error # is <%=Split(Request.ServerVariables("QUERY_STRING"),";")
    > > (0)%><br>
    > > The bad page is <%=Split(Request.ServerVariables("QUERY_STRING"),";")
    > > (1)%><br>
    > >
    > > It returns the following:
    > >
    > > The error # is 404
    > > The bad page is http://localhost/blah.asp
    > >
    > > The address it shows in the address bar is
    > > [http://localhost/Errors/Error.asp?404;http://localhost/blah.asp].
    > >
    > > I tried running your code, and it returns nothing (since the querystring
    > > is being stripped on forwarding).
    > >
    > > Thanks,
    > > Scott

    >
    >
    Ray at, Apr 12, 2004
    #10
  11. I'm running IIS 6.0 at www.aspfaq.com, and my 404 handler is certainly
    capable of retaining the original querystring information:

    http://www.aspfaq.com/blat.asp?foo=bar&x=1

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:...
    > I'm beginning to suspect that the behavior is different in IIS6 in WS2003.
    > Unfortunately, where I am, the only WS2003 servers don't have IIS on them,
    > and I can't install it. I think I'll have to install 2003 on my intranet
    > server tomorrow. ;]
    Aaron Bertrand [MVP], Apr 13, 2004
    #11
    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. news.microsoft.com

    404's, aspxerrorpath, and querystring variables

    news.microsoft.com, Jun 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,520
    news.microsoft.com
    Jul 21, 2004
  2. Jonathan Folland
    Replies:
    2
    Views:
    1,623
    Jonathan Folland
    Mar 17, 2005
  3. Mehdi
    Replies:
    6
    Views:
    36,106
    sloan
    Apr 6, 2006
  4. Radu
    Replies:
    1
    Views:
    283
  5. Sal
    Replies:
    1
    Views:
    406
Loading...

Share This Page