I am having a problem using MVC's Redirect
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:
proxy.host.com/legacy/{whatever} => host.com:81/{whatever}
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:
public class ApplicationController
{
[AllowAnonymous]
public ActionResult TestRedirect(string returnUrl)
{
return this.Redirect("http://AnotherDomain.com/SomeRoute");
}
}
If I invoke this endpoint like so:
http://proxy.host.com/legacy/Application/TestRedirect
and use a tool like Fiddler to capture the traffic I see the result of calling this endpoint is this:
HTTP/1.1 302 Found
Location: proxy.host.com/Application/SomeRoute
//... Other data omitted for simplicity
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://anotherDomain.com/Application/SomeRoute">here</a>.</h2>
</body></html>
As you can see the body of the response has the expected domain (which was passed in to the Redirect
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 Redirect()
. That is, I would expect the response to look like this:
HTTP/1.1 302 Found
Location: http://anotherDomain.com/Application/SomeRoute
//... Other data omitted for simplicity
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://anotherDomain.com/Application/SomeRoute">here</a>.</h2>
</body></html>
I should add that if I turn off the proxy or I bypass it by calling host.com:81/Application/TestRedirect
the method works as expected and the response Location header matches the response body.
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?
Thanks.