title: How does Kestrel know the virtual directory it is running under in IIS?
body: <p>We are trying to migrate our aspnetcore web apps from our own Windows/IIS server to AWS using ECS and API Gateway.  We have everything working but ran into an unexpected issue with redirects inside our web applications.  Our web site is setup like this in IIS:</p>
  
  <pre><code>/ =&gt; the root website is pointing to another web app
  /app1 =&gt; app1 is setup as a virtual directory pointing to an empty folder
  /app1/v1 =&gt; v1 is setup as an application pointing to an aspnetcore app
  /app2/v1 =&gt; again v1 is setup as an application pointing to a different aspnetcore app
  </code></pre>
  
  <p>I have a very simple out of the box aspnetcore application that is setup as a virtual directory under /app1/v1.  The routes in the aspnetcore application are:</p>
  
  <pre><code>/Web
  /Web/Login
  /Web/Home
  </code></pre>
  
  <p>When a user first visits the site (<a href="http://localhost/app1/v1/Web" rel="nofollow noreferrer">http://localhost/app1/v1/Web</a>) they are redirected to the login page using:</p>
  
  <pre><code>Redirect("~/Web/Login")
  </code></pre>
  
  <p>When the application is run by IIS that results in the browser being redirected to:</p>
  
  <pre><code>http://localhost/app1/v1/Web/Login
  </code></pre>
  
  <p>However when I use a reverse proxy, like AWS API Gateway, that has been setup with the same virtual path it redirects to:</p>
  
  <pre><code>http://localhost/Web/Login
  </code></pre>
  
  <p>I'm guessing that there must be a configuration value that I need to pass into Kestrel during startup or as a request header to tell it to add "/app1/v1/" to any ~/ redirects that it performs?.  Does anyone know how IIS is telling Kestrel the full path and how I can replicate that behavior?</p>