title: Redirect stuck after initial redirect within middleware .net core
body: <p>Having a strange issue in .net core 
  I've created some custom middleware to redirect to an install action under certain circumstances. </p>
  
  <p>Within my startup.cs I've added the middleware above the app.UseMvc middleware;</p>
  
  <pre><code> app.SetInstall();
   app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
  </code></pre>
  
  <p>This is my invoke method inside my SetInstall middleware </p>
  
  <pre><code>public async Task Invoke(HttpContext context)
      {
  
  
          if (isInstallerRunInstance())
          {
              if (!context.Request.GetEncodedUrl().Contains("install"))
              {
                  context.Response.Redirect("/install", false);
              }
          }
  
          await _next.Invoke(context);
      }
  </code></pre>
  
  <p>isInstallerRunInstance checks the underlying system to see if this is a candidate for the install action. 
  If it is, and the install url hasn't been called, it will redirect to the install method.</p>
  
  <p>This works ok - my problem occurs with subsequent requests.
  Having completed this initial redirect via the root to install , I try a root request, it still redirects to /install even though the install has completed and isInstallerRunInstance returns false.</p>
  
  <p>To further debug this, I placed the following line into the invoke method at the top before any other code is executed in the method;</p>
  
  <pre><code>   var url = context.Request.GetEncodedUrl();
  </code></pre>
  
  <p>The debugger tells me the url is <a href="http://localhost:8000/install" rel="nofollow noreferrer">http://localhost:8000/install</a>, even though I requested the root and no redirect has been requested at this point. </p>
  
  <p>Even more baffling - If I then go back to startup.cs and comment out the use of my middleware entirely then clean and rebuild the problem remains. I debug and request the root path, it still redirects to /install.
  There doesn't appear to be any localhost cookies, I can't see anywhere this could be cached. </p>
  
  <p>Perhaps there is something I am missing regarding the Redirect method or default caching in .net core. </p>
  
  <p>I'm totally mystified. Any help, please? </p>