简体   繁体   English

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

[英]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 . 假设我有一个通过http://www.mypage.com/test.aspx访问的远程页面。 On that page I use the code Request.ServerVariables["HTTP_HOST"].ToString(). 在该页面上,我使用代码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 ? 当我访问该页面时,代码是否可以返回与我在http://www.mypage.com/test.aspx的网址栏中看到的网址不同的网址? Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

You could see any name that IIS has bound to your web instance. 您可以看到IIS绑定到您的Web实例的任何名称。 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. 因此,如果您的服务器名为“ 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. 要查找绑定的名称,请打开“ Internet信息服务(IIS)管理器”(开始,管理工具),展开树,直到看到您的站点。 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). 如果他们都说[IP address:]“所有未分配”,则您的HTTP_HOST可能是1.通过DNS配置的WWW地址,2.计算机名称3. IP地址。

I was also facing the issue with HttpContext.Current.Request.ServerVariables["HTTP_HOST"] and figured it out. 我还遇到了HttpContext.Current.Request.ServerVariables [“ HTTP_HOST”]的问题,并弄清楚了。 The best way to retrieve the hostname is "HttpContext.Current.Request.Url.Host". 检索主机名的最佳方法是“ HttpContext.Current.Request.Url.Host”。 It resovled my issue. 它解决了我的问题。

Thanks, Raj 谢谢,拉杰

try to use: 尝试使用:

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

i hope that this will be work. 我希望这会起作用。

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的值。

Someone has already mentioned local rewriters (isapi_rewrite), but there are also remote ones, like an ISA Server publishing your server. 有人已经提到本地重写器(isapi_rewrite),但是也有远程重写器,例如发布服务器的ISA Server。 It's a configuration thingie to send original host headers (what the client entered), or the ones entered in the publishing settings. 发送原始主机头(客户端输入的内容)或在发布设置中输入的主机头是配置内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么HttpContext.Request.Url和Request.ServerVariables [“ HTTP_HOST”]返回不同的值 - why does HttpContext.Request.Url and Request.ServerVariables[“HTTP_HOST”] return different values 为什么Request.ServerVariables [“HTTP_HOST”]与Request.Url.Host不同? - Why is Request.ServerVariables[“HTTP_HOST”] different from Request.Url.Host? Request.ServerVariables["HTTP_REFERER"].ToString() 在 IE11 中不起作用 - Request.ServerVariables["HTTP_REFERER"].ToString() is not working in IE11 Request.UserHostAddress和Request.ServerVariables [“REMOTE_ADDR”]之间有什么区别.ToString() - What is the difference between Request.UserHostAddress and Request.ServerVariables[“REMOTE_ADDR”].ToString() Request.ServerVariables函数 - Request.ServerVariables in function 我可以使用哪些策略将变量添加到Request.ServerVariables - What strategies are available to me to add variables to Request.ServerVariables Request.ServerVariables抛出NullReferenceException - Request.ServerVariables throws NullReferenceException 什么时候使用Request.UrlReferrer?何时使用Request.ServerVariables [“ HTTP_REFERER”]? - When to use Request.UrlReferrer and when Request.ServerVariables[“HTTP_REFERER”]? 在request.servervariables()中添加自定义标头 - Add custom header in request.servervariables() 适用于PHP的Request.ServerVariables [LOGON_USER] - Request.ServerVariables[LOGON_USER] for PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM