是否有可能Request.ServerVariables [“HTTP_HOST”]。ToString()可以返回与我在url栏中看到的不同的主机

时间:2021-11-24 02:07:15

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.

假设我通过http://www.mypage.com/test.aspx访问了一个远程页面。在该页面上,我使用代码Request.ServerVariables [“HTTP_HOST”]。ToString()。是否有可能当我访问该页面时,代码可以返回一个不同于我在url栏中看到的url http://www.mypage.com/test.aspx?任何帮助,将不胜感激。谢谢。

5 个解决方案

#1


3  

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.

您可以看到IIS已绑定到Web实例的任何名称。因此,如果您的服务器名为“server1”且IP地址为123.123.123.123,并且所有这三个服务器都绑定到您的IIS实例,您可以看到任何这些值。

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

要查找绑定的名称,请打开“Internet信息服务(IIS)管理器”(启动,管理工具),展开树,直到看到您的站点。找到你正在使用的那个。右键单击并选择“绑定”。编辑列表中的每个绑定。如果他们都说[IP地址:]“全部未分配”,那么您的HTTP_HOST可能是1.您通过DNS配置的WWW地址,2。机器名称3. IP地址。

#2


1  

try to use:

尝试使用:

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

HttpContext.Current.Request.ServerVariables [ “SERVER_NAME”]

i hope that this will be work.

我希望这会有效。

#3


1  

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.

我也遇到了HttpContext.Current.Request.ServerVariables [“HTTP_HOST”]的问题,并想出来了。检索主机名的最佳方法是“HttpContext.Current.Request.Url.Host”。它重新解决了我的问题。

Thanks, Raj

谢谢,拉吉

#4


0  

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

有可能,是的。在您自己的代码能够检查之前,isapi_rewrite模块可以修改HTTP_HOST的值。

#5


0  

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.

有人已经提到了本地重写器(isapi_rewrite),但也有远程的,比如ISA Server发布你的服务器。发送原始主机头(客户端输入的内容)或在发布设置中输入的主机头是一种配置方式。

#1


3  

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.

您可以看到IIS已绑定到Web实例的任何名称。因此,如果您的服务器名为“server1”且IP地址为123.123.123.123,并且所有这三个服务器都绑定到您的IIS实例,您可以看到任何这些值。

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

要查找绑定的名称,请打开“Internet信息服务(IIS)管理器”(启动,管理工具),展开树,直到看到您的站点。找到你正在使用的那个。右键单击并选择“绑定”。编辑列表中的每个绑定。如果他们都说[IP地址:]“全部未分配”,那么您的HTTP_HOST可能是1.您通过DNS配置的WWW地址,2。机器名称3. IP地址。

#2


1  

try to use:

尝试使用:

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

HttpContext.Current.Request.ServerVariables [ “SERVER_NAME”]

i hope that this will be work.

我希望这会有效。

#3


1  

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.

我也遇到了HttpContext.Current.Request.ServerVariables [“HTTP_HOST”]的问题,并想出来了。检索主机名的最佳方法是“HttpContext.Current.Request.Url.Host”。它重新解决了我的问题。

Thanks, Raj

谢谢,拉吉

#4


0  

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

有可能,是的。在您自己的代码能够检查之前,isapi_rewrite模块可以修改HTTP_HOST的值。

#5


0  

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.

有人已经提到了本地重写器(isapi_rewrite),但也有远程的,比如ISA Server发布你的服务器。发送原始主机头(客户端输入的内容)或在发布设置中输入的主机头是一种配置方式。