Why does the reverse proxy rewrite rule stop working when System.Web.Routing is active?
Boil to the highest possible rule:
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^external/(.*)" />
<action type="Rewrite" url="http://some-site/{R:1}" />
</rule>
("Enable proxy" is checked in the server-level ARR proxy settings).
The above rewrite rule works fine in a very simple test application with a web.config containing a section, it works fine in a web forms application, but if I put the same rule in an MVC3 application (on the same machine, so identical configuration for IIS above), it never has any effect; the request flows through.
if it just rewrite (not a reverse proxy) it works fine, for example
<rule name="rewrite to internal" stopProcessing="true">
<match url="^internal/(.*)" />
<action type="Rewrite" url="different-internal/{R:1}" />
</rule>
... well.
I can get the reverse proxy rule to work if I add
routes.IgnoreRoute("external/{*pathInfo}");
in the Global.asax.cs class, so my request for the outer / * doesn't go to the default controller, but I don't understand why. I think the url rewrite module runs before routing (see http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/ ), so I expect that in between there will be no conflict.
Is the routing module adding in "virtual" rewrite rules to the URL rewriting module that override my declared rewrite rules?
source to share
I had the same problem and it took me all day to find a solution.
-
Find: ServoceModel tag in Web.config file and add serviceHostingEnvironment code as shown below:
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel>
This will allow routes to be passed to IIS for processing.
Another tip, I recommend anyone who has routing issues with their MVC projects install the Remote Debugger via NuGet. This will show you which routes are activated when.
source to share