Pulling the querystring off a 404 redirect

S

Scott McNair

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
 
R

Ray at

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
 
S

Scott McNair

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

Ray at

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
 
S

Scott McNair

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
 
E

Evertjan.

Ray at said:
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
 
R

Ray at

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
 
S

Scott McNair

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
 
R

Ray at

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 said:
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





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
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top