homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

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)

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" -->

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




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




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

Thanks for that.


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

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


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)

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


 4:16 am on Oct 25, 2011 (gmt 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)

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)

What Web browser are you using by chance?


 1:03 am on Oct 26, 2011 (gmt 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)

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)

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)

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


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


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.

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)

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)

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)

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)

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)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved