Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard hostname in IIS Express + VS 2015

I have a multi-tenant application that is accessed in production as customer.ourdomain.com. For local development with IIS, we use a custom wildcard domain, company-localdev.com.

With IIS, this works without any particular configuration. IIS Express, on the other hand, only binds to localhost.

We have an ongoing migration project to ASP.NET 5, and we'd like to use IIS Express for an easier developer experience.

Is it possible to have IIS Express listen to *.company-localdev.com:1234? Bonus points if this can be automated so a developer can have it working just by opening the solution in IIS.

like image 435
Diego Mijelshon Avatar asked May 14 '15 16:05

Diego Mijelshon


3 Answers

I had this exact same issue with IIS Express in Visual Studio 2019. MSDN held the answer.

The value of this property is a colon-delimited string that includes the IP address, port, and host name of the binding. You can leave the host name blank.

This simple binding will accept all hostnames

<bindings>
    <binding protocol="http" bindingInformation="*:1234:" />
</bindings>
like image 62
Adam Avatar answered Sep 23 '22 22:09

Adam


In ASP.NET 5 / vNext, the config file is found in

~ProjectFolder~/.vs/config/applicationhost.config

From there, you can add new bindings like rdans explained.

like image 15
Inrego Avatar answered Nov 20 '22 03:11

Inrego


Ok I got it working on my local machine, here are all the steps I had to take:

  1. Go to {YourProjectFolder}\.vs\config and edit the applicationhost.config file:

        <site name="MySite" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="{MyProjectFolderPath}" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:49861:localhost" />
                <binding protocol="http" bindingInformation="*:80:example.com" />
                <!-- for subdomain testing only -->
                <binding protocol="http" bindingInformation="*:80:sub1.example.com" />
                <binding protocol="http" bindingInformation="*:80:sub2.example.com" />
            </bindings>
        </site>
    
  2. Run Notepad as Administrator and go to C:\Windows\System32\drivers\etc to open the hosts file and amend it like so

    127.0.0.1 example.com
    127.0.0.1 sub1.example.com
    127.0.0.1 sub2.example.com

  3. Add the url reservation by running cmd.exe as Administrator and typing in the netsh http prompt (to get the netsh http> prompt, you must type netsh followed by Enter, then http followed by Enter):

    add urlacl url=http://example.com:80/ user=everyone

    add urlacl url=http://sub1.example.com:80/ user=everyone

    add urlacl url=http://sub2.example.com:80/ user=everyone

Bear in mind that the keyword everyone depends on the language of your Windows OS. On a French OS, user=everyone shall be replaced by user="Tout le monde", on a German OS it should be user=jeder, in Spanish user=todos etc... you get the idea.

  1. Then after that you should be able to start debugging and navigate to the domain you have setup to see your website.

Hope this helps.

like image 15
Darxtar Avatar answered Nov 20 '22 04:11

Darxtar