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.
-
sorry? what the difference between this values? – Andrei Andrushkevich Jan 05 '11 at 20:38
-
I'm trying to debug a remote site in which I don't have access to the server. on one of the pages it's using the code specified above to try to open a file. Unfortunately when it tries to open the file it can't find it, and I'm wondering if it could be due to the code above. I already checked and the file is on the server. – Ben Jan 05 '11 at 20:44
-
When I am trying to open a file on the server, I usually use Server.MapPath["."] to get the path to the current folder (on the server). – tgolisch Jan 05 '11 at 21:02
5 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).

- 6,549
- 3
- 24
- 42
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

- 11
- 1
try to use:
HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
i hope that this will be work.

- 9,905
- 4
- 31
- 42
It is possible, yes. A isapi_rewrite module could modify the value of HTTP_HOST before your own code is able to inspect it.
-
do you know if it's possible that my code could be running and grabbing the url before the isapi_rewrite? – Ben Jan 05 '11 at 20:47
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.

- 19,501
- 3
- 53
- 95