Search code examples
asp.net-mvciis-express

How to serve two ASP.Net MVC applications on the same IIS Express instance?


I have two ASP.Net MVC applications, let's say Site1 and Site2.

For now, I can successfully access Site1 by visiting http://localhost/

Here's my IIS Express applicationhost.config file:

<sites>
   <site name="Site1" id="1" serverAutoStart="true">
       <application path="/">
           <virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\Site1" />
       </application>
       <bindings>
           <binding protocol="http" bindingInformation=":80:localhost" />
           <binding protocol="http" bindingInformation=":80:10.49.0.137" />
       </bindings>
   </site>
   <siteDefaults>
       <logFile logFormat="W3C" directory="%IIS_USER_HOME%\logs" />
       <traceFailedRequestsLogging directory="%IIS_USER_HOME%\logs\tracelogfiles" enabled="false" maxLogFileSizeKB="1024" />
   </siteDefaults>
   <applicationDefaults applicationPool="IISExpressAppPool" />
   <virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>

What I want now is:

  • Access Site1 on http://localhost/Site1
  • Place Site2 on %IIS_USER_HOME%\wwwroot\Site2
  • Access Site2 on http.//localhost/Site2

How should I change the above applicationhost.config to achieve what I want?

Thanks.


Solution

  • change your applicationhost.config as shown below and restart IIS Express.

    <sites>    
      <site name="Site1" id="1" serverAutoStart="true">
       <application path="/">            
          <virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\" />
       </application>        
       <application path="/site1">            
          <virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\Site1" />
       </application>        
       <application path="/site2">            
          <virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\Site2" />
       </application>        
       <bindings>            
         <binding protocol="http" bindingInformation=":80:localhost" />            
         <binding protocol="http" bindingInformation=":80:10.49.0.137" />        
       </bindings>    
      </site>    
      <siteDefaults>        
        <logFile logFormat="W3C" directory="%IIS_USER_HOME%\logs" />        
        <traceFailedRequestsLogging directory="%IIS_USER_HOME%\logs\tracelogfiles" enabled="false" maxLogFileSizeKB="1024" />    
      </siteDefaults>    
      <applicationDefaults applicationPool="IISExpressAppPool" />    
      <virtualDirectoryDefaults allowSubDirConfig="true" /> 
    </sites>