Welcome to WebmasterWorld Guest from 54.167.83.224

Forum Moderators: ocean10000

Message Too Old, No Replies

Referring URL messages for ASP 404 error page

How do I carry out the same function as #echo var in ASP?

     
1:22 am on Oct 16, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


I use a few bits of code in my error 404 pages on a Linux servers. But I would also like to be able to replicate this on an IIS server.

Does anyone know a way to do the following Linux/Apache commands on an IIS hosted website? I’ve been banging my head on the table trying to get this to work, but I’ve never really got my head around it.

Previous location
<!--#echo var="HTTP_REFERER" -->


Requested URL
<!--#echo var="REQUEST_URI" --> 


IP address
<!--#echo var="REMOTE_ADDR" -->


Browser
<!--#echo var="HTTP_USER_AGENT" -->


Thanks
6:19 am on Oct 16, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


Request.ServerVariables("HTTP_REFERER")

[w3schools.com...]
11:56 am on Oct 16, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Thanks for that.
1:59 am on Oct 17, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Hmmm. For some reason I am getting 'StartTag: invalid element name‘ errors for this;

<%Response.Write(Request.ServerVariables("URL"))%>


It works OK, if I call the 404.asp page directly by typing it into the browser bar. But when used as an error page, it gives the above error.

Any ideas anyone?
1:35 pm on Oct 17, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


try this instead.
<% = Request.ServerVariables("URL")%>
4:16 am on Oct 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Thanks for that suggestion.

Same problem, unfortunately. How irritating. The page loads, but stops loading at the point where that line of ASP code starts.
5:37 am on Oct 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


I don’t know if it means anything, but it also gives those errors if it finds any ‘loose’ </span> tags in the document.
11:34 pm on Oct 25, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


What Web browser are you using by chance?
1:03 am on Oct 26, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Safari on a Mac. I didnt think to check it on another browser, but will do so later.
1:04 am on Nov 2, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


OK, I’ve tried this on Firefox on a Mac - which gives its own error page and IE 8 on W7, which loads the page fine, but simply disregards any of the ASP.
1:36 pm on Nov 2, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


I just had a thought.

The actual error page, is the file extension aspx or asp or html?

If it is html extension IIS will not run any server side scripts. Which I think may be the actual problem you are seeing.

You would have to rename the 404 Page extension to aspx, and update the reference in IIS to point to this version. And retest it.
9:23 pm on Nov 5, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Thanks. The filename is .asp. But I'll try aspx and see if that helps.
5:06 am on Nov 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Hmmmm.

No, unfortunately using .asp or .aspx doesn’t solve the problem.

If I call the page directly e.g. www.example.com/404.aspx then the script ‘seems' to kind of work.

e.g.
Sorry, the page <%Response.Write(Request.ServerVariables("URL"))%> has not been found! 
will display as "Sorry, the page /404.aspx has not been found!".

But if I go to a non-existent page, I get the above errors.
11:37 am on Nov 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


How have you set up the Error page is IIS. Is it as a file or a URL? (if it's set up as a file, it will not run ASP script)
12:26 am on Nov 8, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Aha. Thanks, I'll check that out later. I'm pretty sure I set it as a file.
5:27 am on Nov 8, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


OK, that’s fantastic. It works!

Thanks for all your help people.

Just one final question.

When I try to use
<%Response.Write(Request.ServerVariables("URL"))%>
or
<% = Request.ServerVariables("URL")%>


Instead of returning the url of the page the user was trying to find, it returns the name of the 404 page. E.G.
Sorry, the page /404.asp has not been found
instead of
Sorry, the page /missing.html has not been found
.

Any ideas?
11:16 am on Nov 21, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 14, 2005
posts: 58
votes: 1


The code will not execute if you using the default 404 page as it is a static page (.htm).

Look at this article [support.microsoft.com...]
6:52 am on Dec 21, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 10, 2006
posts:661
votes: 0


Thanks. I am using a static page, with a .asp extension.

What I found is that the code which displays the referring page URL works fine, but the code which displays the sought after page URL doesn’t.

However, as the result of another issue, I’ve discovered that the biggest problem is that this method doesn’t send a 404 error from the server. It actually returns an ‘OK’ found message. So I’ve had to abandon this idea for the time being, and used a .HTML file without any asp code, which sends the correct error. Unless anyone has any suggestions.

Thanks for all the help.