开发者

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

开发者 https://www.devze.com 2022-12-09 13:06 出处:网络
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 开发者_StackOverflow社区a region specific domain. For example

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 开发者_StackOverflow社区a region specific domain. For example:

  • /fr/* should be served from www.domain.fr
  • /uk/* should be serverd from www.domain.co.uk and so on.

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.

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


I think you want Request.Headers["host"]


In some cases you want to know from the host who sent de request, so I used this

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

精彩评论

暂无评论...
验证码 换一张
取 消