views:

1097

answers:

3

I am maintaining a classic asp application and while going over the code I came across two similar lines of code:

request.serverVariables("URL")
''# Output: "/path/to/file.asp"

request.serverVariables("SCRIPT_NAME")
''# Output: "/path/to/file.asp"

I don't get it... what is the difference? both of them ignore the URL rewriting that I have set up which puts the /path folder as the root document (the above URL is rewritten to "/to/file.asp")

More info: The site is deployed on IIS 7

PS I commented the lines like this to make the stack overflow syntax highlighting work properly:

''# This is a comment in asp, and is displayed like one
' This makes everything after it appear like a string until it finds another
' <-- one of those
+1  A: 

Is this maybe there in case of Server.Transfer?

In the case where you do a server.transfer i think you would get different results

i.e. SCRIPT_NAME would be e.g. /path/to.transferredfile.asp whereas URL would remain as /path/to/file.asp

Justin Wignall
No, just tried it. It will both be "/path/to.transferredfile.asp" after Server.Transfer()
Tomalak
+1  A: 

This could be a bug under IIS 7.

I could not get Request.ServerVariables("URL") and Request.ServerVariables("SCRIPT_NAME") to return different values. I've tried the cases where they were called from an included file (<!--#include file="file.asp"-->) or after a Server.Transfer.

çağdaş
maybe they're just both kept for backwards compatibility?
Jiaaro
@Jim Robert,I'm not sure to be honest. I've now tried different variations (calling a sub/function that outputs URL and SCRIPT_NAME) but still, they always return the same value. Again, this is tested under IIS 7.
çağdaş
A: 

URL Gives the base portion of the URL, without any querystring or extra path information. For the raw URL, use HTTP_URL or UNENCODED_URL.

SCRIPT_NAME A virtual path to the script being executed. Can be used for self-referencing URLs.

See, http://www.requestservervariables.com/url and /script_name for the definitions.

Max Wikström