Welcome to WebmasterWorld Guest from 54.144.126.195

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?

     

bouncybunny

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

WebmasterWorld Senior Member 5+ Year Member



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

marcel

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

WebmasterWorld Senior Member 10+ Year Member



Request.ServerVariables("HTTP_REFERER")

[w3schools.com...]

bouncybunny

11:56 am on Oct 16, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Thanks for that.

bouncybunny

1:59 am on Oct 17, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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?

Ocean10000

1:35 pm on Oct 17, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try this instead.
<% = Request.ServerVariables("URL")%>

bouncybunny

4:16 am on Oct 25, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.

bouncybunny

5:37 am on Oct 25, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I donít know if it means anything, but it also gives those errors if it finds any Ďlooseí </span> tags in the document.

Ocean10000

11:34 pm on Oct 25, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What Web browser are you using by chance?

bouncybunny

1:03 am on Oct 26, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Safari on a Mac. I didnt think to check it on another browser, but will do so later.

bouncybunny

1:04 am on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.

Ocean10000

1:36 pm on Nov 2, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



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.

bouncybunny

9:23 pm on Nov 5, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Thanks. The filename is .asp. But I'll try aspx and see if that helps.

bouncybunny

5:06 am on Nov 7, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.

marcel

11:37 am on Nov 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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)

bouncybunny

12:26 am on Nov 8, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Aha. Thanks, I'll check that out later. I'm pretty sure I set it as a file.

bouncybunny

5:27 am on Nov 8, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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?

wingnut

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

10+ Year Member



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

bouncybunny

6:52 am on Dec 21, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month