简体   繁体   English

"如何从 HttpContext (asp.net) 获取“主机:”标头"

[英]How to get "Host:" header from HttpContext (asp.net)

I need to server parts of my application from different domains.我需要从不同的域为我的应用程序的一部分提供服务器。 To be precise I have a sub section of the site that should be served from a region specific domain.准确地说,我有一个站点的子部分,应该从特定区域的域提供服务。 For example:例如:

  • \/fr\/* should be served from www.domain.fr \/fr\/* 应该从 www.domain.fr 提供<\/li>
  • \/uk\/* should be serverd from www.domain.co.uk and so on. \/uk\/* 应该从 www.domain.co.uk 等提供服务器。<\/li><\/ul>

    I'd like to make a route entry that will redirect the request with wrong domain to the correct domain.我想创建一个路由条目,将带有错误域的请求重定向到正确的域。 But I don't know how to access http header information form HttpContext.但我不知道如何从 HttpContext 访问 http 头信息。

    Any help is welcome.欢迎任何帮助。

    "

string requestedDomain = HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
string requestScheme = HttpContext.Current.Request.Url.Scheme;
string requestQueryString = HttpContext.Current.Request.ServerVariables["QUERY_STRING"];
string requestUrl = HttpContext.Current.Request.ServerVariables["URL"];

HttpContext.Current.Request.Url.Host

我想你想要 Request.Headers["host"]

在某些情况下,您想从发送 de 请求的主机那里知道,所以我使用了这个

 stsring _Host = HttpContext.Request.Headers["Referer"];

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM