开发者

Running multiple IIS Express instances on the same port through Visual Studio

I currently have sites configured in IIS Express for each of the applications I've been working on. Each of them are set to run locally on ports 80 and 443, but have separate bindings (http://site1/ and http://site2/) with those aliases pointing locally from within my hosts file.

I can start these sites at the same time when launching IIS Express directly (from the command line), but letting VS2010 launch them whe开发者_如何转开发n debugging is unsuccessful. The first site will launch and debug as it should, but the second site to start generates an error: "Unable to launch the IIS Express Web server. Port '80' is in use."

Here's the IIS Express configuration I'm using (slightly modified to remove project names):

<site name="Site1" id="1" serverAutoStart="true">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="Site1Path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:80:Site1" />
        <binding protocol="https" bindingInformation="*:443:Site1" />
    </bindings>
</site>
<site name="Site2" id="2" serverAutoStart="true">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="Site2Path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:80:Site2" />
        <binding protocol="https" bindingInformation="*:443:Site2" />
    </bindings>
</site>

It would appear that VS is doing a check for anything currently listening on port 80, whereas IIS Express isn't restricted in that fashion. I can still have VS attach to the instances of IIS Express that were started by command line, but I'd prefer to have VS manage them.

Is this a limitation on how VS2010 handles IIS Express, and if so, what's a good workaround?


You are right... this is VS2010 limitation. I am not sure if the following workaround works for you or not.

You can have single site with multiple applications as shown below.

<site name="MySite" id="1" serverAutoStart="true">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="SiteRoot" />
    </application>
    <application path="/Site1" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="Site1Path" />
    </application>
    <application path="/Site2" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="Site2Path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:80:Site1" />
        <binding protocol="https" bindingInformation="*:443:Site1" />
    </bindings>
</site>

and then you can access them as http://localhost/site1 and http://localhost/site2


beginning of binding collection of each site seems to be an error in the case of same port visual studio. Run from the visual studio was can be done by adding a binding that specifies the different ports.

<site name="Site1" id="1" serverAutoStart="true">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="Site1Path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:44300:Site1" />
        <binding protocol="http" bindingInformation="*:80:Site1" />
    </bindings>
</site>
<site name="Site2" id="2" serverAutoStart="true">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="Site2Path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:44301:Site2" />
        <binding protocol="http" bindingInformation="*:80:Site2" />
    </bindings>
</site>

<binding protocol="http" bindingInformation="*:44300:Site1" />

<binding protocol="http" bindingInformation="*:44301:Site2" />

Running http://Site1/ http://Site2/ and http://Site1:44300/ http://Site2:44301

netsh http add urlacl url=http://Site1:44300/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜