title: Why does ASP.NET MVC's Redirect method sets wrong Location header when running the application behind a proxy?
body: <p>I am having a problem using MVC's <code>Redirect</code> method. I am running my MVC4 web application behind a simply IIS proxy. The IIS proxy has one simple rewrite rule that is used so that the site can be accessed under a folder called 'legacy'. The rule looks like this:</p>
  
  <pre><code>proxy.host.com/legacy/{whatever} =&gt; host.com:81/{whatever}
  </code></pre>
  
  <p>However in some situations I need to redirect to domains that are in an entirely different domain where the proxy rules don't apply. I created a simple endpoint that does a redirect to an external domain:</p>
  
  <pre><code>public class ApplicationController
  {
      [AllowAnonymous]
      public ActionResult TestRedirect(string returnUrl)
      {
          return this.Redirect("http://AnotherDomain.com/SomeRoute");
      }
  }
  </code></pre>
  
  <p>If I invoke this endpoint like so:</p>
  
  <pre><code>http://proxy.host.com/legacy/Application/TestRedirect
  </code></pre>
  
  <p>and use a tool like Fiddler to capture the traffic I see the result of calling this endpoint is this:</p>
  
  <pre><code>HTTP/1.1 302 Found
  Location: proxy.host.com/Application/SomeRoute
  //... Other data omitted for simplicity
  
  &lt;html&gt;&lt;head&gt;&lt;title&gt;Object moved&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
  &lt;h2&gt;Object moved to &lt;a href="http://anotherDomain.com/Application/SomeRoute"&gt;here&lt;/a&gt;.&lt;/h2&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>As you can see the body of the response has the expected domain (which was passed in to the <code>Redirect</code> method but the Location header does not contain the same domain. I would expect the location header to contain the domain that was passed into <code>Redirect()</code>. That is, I would expect the response to look like this:</p>
  
  <pre><code>HTTP/1.1 302 Found
  Location: http://anotherDomain.com/Application/SomeRoute
  //... Other data omitted for simplicity
  
  &lt;html&gt;&lt;head&gt;&lt;title&gt;Object moved&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
  &lt;h2&gt;Object moved to &lt;a href="http://anotherDomain.com/Application/SomeRoute"&gt;here&lt;/a&gt;.&lt;/h2&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>I should add that if I turn off the proxy or I bypass it by calling <code>host.com:81/Application/TestRedirect</code> the method works as expected and the response Location header matches the response body.</p>
  
  <p>Can someone please explain why I am getting the unexpected result of the Location header in the response differing from the response body? How can I get the redirect to work as expected?</p>
  
  <p>Thanks.</p>