request.serverVariables() "URL" vs "Script_Name"
Asked Answered
O

3

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

Ordway answered 27/3, 2009 at 12:53 Comment(0)
O
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.

Oniskey answered 27/3, 2009 at 21:38 Comment(2)
maybe they're just both kept for backwards compatibility?Ordway
@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.Deuteragonist
A
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.

Acerbate answered 23/9, 2010 at 10:41 Comment(1)
That website is one of the least explanatory sites I've ever seen. Looks pretty though.Tricot
O
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.

Oniskey answered 27/3, 2009 at 21:38 Comment(2)
maybe they're just both kept for backwards compatibility?Ordway
@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.Deuteragonist
G
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

Gullett answered 27/3, 2009 at 12:59 Comment(1)
No, just tried it. It will both be "/path/to.transferredfile.asp" after Server.Transfer()Doglike

© 2022 - 2024 — McMap. All rights reserved.