user1253073
user1253073

Reputation: 404

IIS Express - Visual Studio - Running multiple sites on the same port

I have multiple APIs that use the same port (8888). These APIs are part of different solutions.

http://localhost:8888/api1

http://localhost:8888/api2

....

When I run any of the APIs in visual studio 2013 (hit F5), iis express starts and all of the APIs are running. This happens even though the APIs are part of different solution. I can see them when I click on the iis express icon under View Sites.

I installed VS 2015 and when I run one API in visual studio the other APIs do not run. I cannot even run the other APIs in the other solution since I get:

unable to launch iis express.. port is in use

how can I get the other APIs to run when I run any API? I need to mimic the behavior that exists in VS 2013 in VS 2015.

Thanks.

Upvotes: 9

Views: 12937

Answers (3)

Lex Li
Lex Li

Reputation: 63173

If you do want the old behavior, use global application host file in your project file please,

<UseGlobalApplicationHostFile>True</UseGlobalApplicationHostFile>

http://blog.majcica.com/2018/03/15/using-global-application-host-file-in-visual-studio-2015/

Upvotes: 2

Ike Rolfe
Ike Rolfe

Reputation: 43

Update to this in Visual Studio 15+ the IIS config folder is in the projects hidden .vs folder [ProjectFolder]/.vs/[ProjectName]/config/applicationhost.config Other than that, Ivor's Answer still worked for me.

Upvotes: 3

ivor
ivor

Reputation: 136

I solved this for a similar scenario, although in my case I chose to run IISExpress via the command line and passed through the config file as an argument.

  1. Edit the applicationhost.config file. I found mine via the folder path %USERPROFILE%\Documents\IISExpress\config
  2. Locate the <sites> section (found under <system.applicationHost>)

As an example, I have two applications that I want to host simultaneously on port 80 on localhost:

<sites>
    <site name="test" id="1" serverAutoStart="true">
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="C:\codepath" />
        </application>
        <application path="/api1" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="C:\codepath\api1" />
        </application>
        <application path="/api2" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="C:\codepath\api2" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation=":80:localhost" />
        </bindings>
    </site>
<!-- other settings  relevant to your installation of IISExpress-->
</sites>

The key things I had to do to get this working was:

  1. Make sure applicationhost.config is well-formed XML
  2. Make sure you specify the root path in addition to the two api application paths
  3. serverAutoStart="true" ensures the site starts when IISExpress is called
  4. All the applications share the same applicationPool
  5. I defined just one site and bundled in all my applications as sub paths

Upvotes: 6

Related Questions