ASP Redirect Base URL Being Rewritten by IIS

asp.netiis-8redirectrewrite

I am attempting to debug, what I think is, an IIS rewrite issue.

I am hosting multiple sites on a single IIS server which is acting as a proxy to Kestrel hosts behind the scenes. That is all working correctly and I haven't been having any issues there.

The issue I am running into is when any of my sites do a return Redirect("http://www.someotherurl.com/") via ASP.NET MVC, the base URL is always rewritten to the URL of my site – this is true even if the URL is completely external to my URL.

If I run the site separately, not within the IIS proxy, the redirect works as I expect, so I know that it's something within IIS.

As far as rules, I have no outbound rules at all right now. For inbound rules, I have (for each one of my sites):

  1. HTTP to HTTPS redirect rule.
  2. A rewrite rule which takes the URLs and rewrites the URL to http://127.0.0.1:port so that the self-hosted services can handle the request appropriately. There is an individual rule per site.

I am very stumped at this point because I don't see any other way redirects would not go to the actual URL that I provide, but IIS seems to be doing something mysterious.

More Information

  1. Request comes in for www.example.net/Documents.
  2. Rule rewrites the URL to 127.0.0.1:port/Documents based on the incoming URL.
  3. Endpoint handles the request.
  4. A redirect response is sent.
  5. The Base URL is converted back to www.example.com no matter what – even if the redirect is to a different domain. I believe this is where the problem is occurring. It seems like IIS does this by default. I'm not sure, however.

Best Answer

Found the answer and wanted to post here in case someone else runs across the issue.

Per https://stackoverflow.com/a/23600821/132528:

Could Application Request Routing be involved? Look at IIS -> Machine or Site -> Application Request Routing Cache -> Server Proxy Settings and uncheck the "Reverse rewrite host in response headers" checkbox. If you do this at the machine level, it'll take effect for all sites. If you do it on a particular site, it'll only take effect for that site, and other sites on the box will be unaffected.