I am currently testing a site with multiple sub domains pointing to the same ASP.NET application, and the routing handles what to do with each request.
For testing, I have added several sub domains to my “hosts file”, e.g. “127.0.0.1 admin.TestDomain.com”, which is working fine.
However, the problem is that when I call any function in c# to get the host name/domain/url (HttpContext.Current.Request.Url…), the host url always comes back with “localhost”, rather than “TestDomain”.
Any ideas why this name is being resolved in this manner, and where I can get hold of “TestDomain.com”?
I think, original host is lost after mapping of domain to IP-adress (localhost) by local operating system with your “host” file.
You can try RawUrl instead to retrieve exact URL typed in browser:
Also you can try to fetch
HTTP_HOSTvariable from userHost:request header, it should contain original host (not address or default host of the server) browser tries to request:Maybe Getting parameters from RawUrl article will be helpful.