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
- /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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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"];
Method 2
HttpContext.Current.Request.Url.Host
Method 3
I think you want Request.Headers[“host”]
Method 4
In some cases you want to know from the host who sent de request, so I used this
stsring _Host = HttpContext.Request.Headers["Referer"];
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0