I thought about it myself. The problem here was not that the HOSTS file did not work, but that I used the wrong method to detect the host header from the browser.
This does NOT work and only repeats the local host 127.0.0.1 on which the ASP development server is running.
Request.Url.Host;
However, using instead, the domain entered into the browser is saved and can be used to dynamically change the behavior of the site even on the ASP development server.
HttpContext.Current.Request.Headers.Get("Host").ToString();
So, the solution for checking multiple domains on the Dev server:
- create several test domains in the HOSTS file on your local machine, pointing to 127.0.0.1
- use Headers.Get ("Host") syntax to sniff the domain entered into the browser.
The only thing I found is that you still have to manually save the specific port on which the ASP dev server is running.
Example: if you have a hosts file www.mytestdomain.com pointing to 127.0.0.1, and your dev server is running on port 46146, then you should enter the following into your browser for testing: http://www.mytestdomain.com : 46146 /
But it still works!
source share