6

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

Albireo
  • 10,977
  • 13
  • 62
  • 96
Jiaaro
  • 74,485
  • 42
  • 169
  • 190

3 Answers3

8

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
  • 131
  • 2
  • 2
3

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ş Tekin
  • 16,592
  • 4
  • 49
  • 58
  • maybe they're just both kept for backwards compatibility? – Jiaaro Mar 30 '09 at 13:04
  • @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ş Tekin Mar 30 '09 at 14:41
1

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
  • 3,490
  • 20
  • 23