Instead of using localhost when you develop some projects locally with Visual Studio and IIS Express you might want/need to use a domain or another string. In my case, I need to have two different domains pointing to the same Umbraco installation to have Umbraco redirect to the correct site
Say, we want to map two URLs – dev.example.de and dev.example.dk – to same local folder. In order to do so we need to do the following
- In windows open the hosts file located at:
%WINDIR%SYSTEM32DRIVERSETCHOSTS
- Add the following code to the file. This tells Windows to route the URLs to 127.0.0.1
127.0.0.1 dev.example.de 127.0.0.1 dev.example.dk
- Now, open Visual Studio as an Administrator and then your project. Go to Properties > Web
- Note the port number under Servers – it should look something like localhost:58733
- Under Servers choose IIS Express in the dropdown. Set project Url to http://localhost/ and press the Create Virtual Directory button. (If you get an error here you might need to disable IIS or change the port on the Default Site in IIS to anything but port :80).
- Also under Servers check the Override application root URL and enter http://dev.example.de
- In the same panel under Start Action set the Start Url to http://dev.example.de.
- Save the file
- Now, open the applicationhost.config located at
%USERPROFILE%My DocumentsIISExpressconfigapplicationhost.config
- find the site with the port number noted earlier (in my case 58733) and change the line that says <binding protocol=”http” bindingInformation=”*:58733:localhost” /> to <binding protocol=”http” bindingInformation=”*:80:dev.example.de” /> <binding protocol=”http” bindingInformation=”*:80:dev.example.dk” /> so the it all looks similar to this
<site name="mysite" id="32"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="C:UserssodamDocumentswebsitesMultisitemysite" /> </application> <bindings> <binding protocol="http" bindingInformation="*:80:dev.example.de" /> <binding protocol="http" bindingInformation="*:80:dev.example.dk" /> </bindings> </site>
- Save the file an go back to Visual Studio.
- Pressing CTRL+F5 should now open a new browser window with http://dev.example.de as url.
- If this works try the other address as well (http://dev.example.dk) – this migth not work yet. If it doesn’t, do the following
- Go back to the IIS settings in Visual Studio and alter the Start URL and the Override application root URL to http://dev.example.dk. Then press CTRL+F5.
- Now both URLs should work. You can of course change it back to http://dev.example.de if you wish that one to be the default URL.
Part of the solution to this was found in this Stack Overflow answer