Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 231
Ben Avatar asked Jan 05 '11 20:01

Ben


2 Answers

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).

like image 56
tgolisch Avatar answered Sep 28 '22 04:09

tgolisch


try to use:

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

i hope that this will be work.

like image 32
Andrei Andrushkevich Avatar answered Sep 28 '22 06:09

Andrei Andrushkevich