title: Hooking up sub applications in ASP.NET Core
body: <p>I have two projects in asp.net core 2.1. One is the main web application, and the other is a sub-application. The sub-application is for the most part, independent; it only needs cookies from the main application.</p>
  
  <p>I'm trying and failing to set up the two projects in my local dev environment, and I will also need to set up for live IIS Deployment in the future. I have both VS projects in the same VS Solution. In their project Debug settings page, I have them both set up to launch IISExpress with app URL as '<a href="http://localhost:44305" rel="nofollow noreferrer">http://localhost:44305</a>'. I have tried setting the subapp to '<a href="http://localhost:44305/subapp" rel="nofollow noreferrer">http://localhost:44305/subapp</a>' too, but when vs run, IISExpress complains that the port is already in use.</p>
  
  <p>I have a web config for both apps. The very basic defaults for both. In the sub app, I have the extra line to remove the aspnetcore handler (as I found from searching).</p>
  
  <pre><code>&lt;remove name="aspNetCore" /&gt;
  </code></pre>
  
  <p>In the sub app, i have also tried adding in startup.cs:</p>
  
  <pre><code>app.UsePathBase("/subapp")
  </code></pre>
  
  <p>The results I get from this setup running in vs locally is that on the base URL, it actually loads up my subapp instead of my main app (browser URL is localhost:44305). Fiddling with multiple settings seems to get me nowhere; either both apps fail to load completely, or one or the other app is inaccessible.</p>
  
  <p>Is there any proper documentation out there for setting up multiple apps to work together locally and in IIS? Everything I seem to find is from pre-2.0.</p>
  
  <p>Thank you for your help!</p>
  
  <p>Edit:
  I actually managed to get a fresh project working as subapp when deploying to IIS. To set up:</p>
  
  <ol>
  <li><p>Make a new VS solution with two aspnetcore 2.1 web applications.</p></li>
  <li><p>Add a web.config to sub application with following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;system.webServer&gt;
      &lt;handlers&gt;
      &lt;/handlers&gt;
      &lt;aspNetCore processPath="dotnet" arguments=".\IISTestSubApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre></li>
  <li><p>No web config for Main app.</p></li>
  <li><p>Add .UseIISIntegration() to Program.cs CreateWebHostBuilder to both apps.</p></li>
  <li><p>In Startup.cs Configure method for Subapp, add <code>app.UsePathBase("/subapp/");</code></p></li>
  <li><p>Deploy main app to a folder /Mainapp. Deploy sub app to /Mainapp/subapp.</p></li>
  <li><p>Set up iis website for main app.</p></li>
  <li><p>Right click on main app website in IIS and click Add Application. Add the subapplication with an alias '/Subapp'</p></li>
  </ol>
  
  <p>That should be all you need. Some of the steps may not be necessary. I haven't fully tested which steps are 100% necessary.</p>
  
  <p>Unfortunately, I still can't get it to work with IISExpress. I have my .vs/applicationhost.config file looks almost exactly like the IIS one, but when running both apps at the same time, i get errors saying that the port is already in use. I'm still trying a bunch of new things, so, we'll see if I can figure it out.</p>