tags:

views:

59

answers:

1

I'm using Windows 2008 x64 R2 with IIS 7.5 and ASP.NET 2.0.

I want to use HTTP_REFERER but for some reason but it's not available so I decided to iterate all the server vars using this code :

foreach (string   vars in Request.ServerVariables)
{
    Response.Write (vars.ToString() + "\r\n <br/>");
}

Here is the result :

ALL_HTTP
ALL_RAW
APPL_MD_PATH
APPL_PHYSICAL_PATH
AUTH_TYPE
AUTH_USER
AUTH_PASSWORD
LOGON_USER
REMOTE_USER
CERT_COOKIE
CERT_FLAGS
CERT_ISSUER
CERT_KEYSIZE
CERT_SECRETKEYSIZE
CERT_SERIALNUMBER
CERT_SERVER_ISSUER
CERT_SERVER_SUBJECT
CERT_SUBJECT
CONTENT_LENGTH
CONTENT_TYPE
GATEWAY_INTERFACE
HTTPS
HTTPS_KEYSIZE
HTTPS_SECRETKEYSIZE
HTTPS_SERVER_ISSUER
HTTPS_SERVER_SUBJECT
INSTANCE_ID
INSTANCE_META_PATH
LOCAL_ADDR
PATH_INFO
PATH_TRANSLATED
QUERY_STRING
REMOTE_ADDR
REMOTE_HOST
REMOTE_PORT
REQUEST_METHOD
SCRIPT_NAME
SERVER_NAME
SERVER_PORT
SERVER_PORT_SECURE
SERVER_PROTOCOL
SERVER_SOFTWARE
URL
HTTP_CONNECTION
HTTP_KEEP_ALIVE
HTTP_ACCEPT
HTTP_ACCEPT_CHARSET
HTTP_ACCEPT_LANGUAGE
HTTP_HOST
HTTP_USER_AGENT
HTTP________________

Can anyone explain why HTTP_REFERER is missing?

+2  A: 

When you test this, make sure you actually browse to the page that prints the Server Variables from another web page. For example, create a new page that has a link such as:

<a href="printservervars.aspx">Click</a>

Which takes you to the page that has the sample code you posted.

IIS won't create HTTP_REFERER unless the browser sends it. The browser won't send it if the first page you open is the one with that script because the browser wasn't 'referred' to that page from anywhere.

Kev