Ben
Ben

Reputation: 784

Is it possible that Request.ServerVariables["HTTP_HOST"].ToString() can return a different host than what I see in the url bar

Say I have a remote page accessed through http://www.mypage.com/test.aspx. On that page I use the code Request.ServerVariables["HTTP_HOST"].ToString(). Is it possible that when I access the page the code can return a different url than that which I see in the url bar which is http://www.mypage.com/test.aspx? Any help would be appreciated. Thanks.

Upvotes: 5

Views: 7413

Answers (5)

Raj
Raj

Reputation: 11

I was also facing the issue with HttpContext.Current.Request.ServerVariables["HTTP_HOST"] and figured it out. The best way to retrieve the hostname is "HttpContext.Current.Request.Url.Host". It resovled my issue.

Thanks, Raj

Upvotes: 1

sisve
sisve

Reputation: 19791

Someone has already mentioned local rewriters (isapi_rewrite), but there are also remote ones, like an ISA Server publishing your server. It's a configuration thingie to send original host headers (what the client entered), or the ones entered in the publishing settings.

Upvotes: 0

Andrei Andrushkevich
Andrei Andrushkevich

Reputation: 9973

try to use:

HttpContext.Current.Request.ServerVariables["SERVER_NAME"]

i hope that this will be work.

Upvotes: 1

user47589
user47589

Reputation:

It is possible, yes. A isapi_rewrite module could modify the value of HTTP_HOST before your own code is able to inspect it.

Upvotes: 0

tgolisch
tgolisch

Reputation: 6734

You could see any name that IIS has bound to your web instance. So, if your server is called "server1" and the IP address is 123.123.123.123 and all three of those are bound to your instance of IIS, you could see any of those values.

To look up what names are bound, open "Internet Information Services (IIS) Manager" (start, Administration tools), expand the tree till you see your sites. Find the one you are using. Right-click and choose "Bindings". Edit each of the bindings in the list. If they all say [IP address:] "All Unassigned", then your HTTP_HOST could be 1. the WWW address that you have configured via DNS, 2. the machine name 3. the IP address(es).

Upvotes: 3

Related Questions