Search code examples
asp.net-mvciisconfigurationiis-express

IIS Express URL binding is not bound as configured?


I have 2 bindings for my app configured in the applicationhost.config like this:

<bindings>
     <binding protocol="http" bindingInformation="*:12692:localhost" />
     <binding protocol="http" bindingInformation="*:80:127.0.0.2" />
</bindings>

As you can see there is one IP binding there, at first there is no ACL setup to allow it so I have to run the VS as admin so that the binding can be done OK (otherwise the app won't run). If I run it as admin I can see the 2 bindings configured OK (they are shown in the IIS Express window accessible from the system tray icon). Now I want it more convenient (not requiring administrative privilege) by adding the IP (for the second binding) to the ACL by using netsh like this:

netsh http add urlacl url=http://127.0.0.2:80/ user=everyone

It reported OK, then I could try reopening the project normally (not as admin) and the app run OK (not any binding error reported) but I could see just one binding (the second binding), the first binding is not configured as expected. Now if I try running the VS as admin again, it still works fine with 2 bindings configured correctly.

So looks like it's just a problem of running VS as admin or not (the ACL configuration is not involved). How could that cause the issue?


Solution

  • it is not a recommended way to modify the applicationhost.config file. another thing is when you open a visual studio you can only see the one site bing in the application property. if you want to use more than two bindings with a site you could use the iis or iisexpress command:

    run command prompt as administrator.

    enter the iisexpress.exe folder path by running below command:

    cd C:\Program Files\IIS Express
    

    then run below command to run iisexpress site:

    iisexpress /config:C:\Users\Administrator\source\repos\webformtest1\.vs\webformtest1\config\applicationhost.config /site:webformtest1(3)
    

    in this way you can see both the binding in iis express tray:

    enter image description here