3
votes

I am facing a dilemma related to another question but not exactly the same.

I want to use IIS Express with a custom URL but without modifying the local HOSTS file.

Specifically, for me, dev.example.com resolves to 127.0.0.1 using DNS (our DNS is set up so that *.example.com resolves to 127.0.0.1). This is what I want to use as a project URL. If I add dev.example.com to my HOSTS file, it works, but if I don't, it doesn't. I'm guessing this is because Visual Studio doesn't recognize this as being a local URL.

Is there a way to not modify the HOSTS file but still use a custom URL like dev.example.com as a Project Url in Visual Studio with IIS Express?

1

1 Answers

3
votes

Yes-sortof. IISExpress configuration is stored in the executing users profile under:

C:\Users\<username>\Documents\IISExpress\config\

You'll need to edit applicationhost.xml

Locate the <sites> section and extend:

        <site name="WebApplication1" id="20">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="C:\inetpub\WebApplication1" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:45965:localhost" />                  
                <binding protocol="http" bindingInformation="*:80:dev.example.com" />
            </bindings>
        </site>

Note that the port 80 must not be occupied by IIS in case it's running on your dev box.

The problem that this solution is facing, that with these settings pressing F5 in VS, or otherwise start the website from VS will ALWAYS want to start on localhost, and will not initialize the other binding. You have to start IISExpress manually with the following:

c:\Program Files (x86)\IIS Express\iisexpress.exe" /site:WebApplication1