After a lot more playing, we found the answer. The issue with Garath's comments above is that, while outbound rules can rewrite Html.ActionLink
and Html.BeginForm
, they cannot do anything for RedirectToRoute
or RedirectToAction
and more. Outbound rules only parse the generated HTML content and change it before sending it back to the browser. Outbound rules are also incompatible with gzip, which is understandable but annoying.
In short, we created a custom rewrite provider that uses the SQL connection to pull the version and return the correct URL. We also hooked into the IIS URL Rewrite capability to send custom server variables to prevent querying the database more than once per session. It works like this:
- Request hits the IIS URL Rewrite module
- First rule checks for a cookie value and, if it exists, rewrites the URL based on that and stops processing further rules.
- If the cookie isn't there, it calls the custom provider, which uses SQL to rewrite the URL.
- The second rule also sets a custom server variable passed in the header to the version.
- The website checks for that header variable, and if set, creates a cookie with the version.
- Rinse and repeat.
Links that helped us out:
- http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module
- http://www.iis.net/learn/extensions/url-rewrite-module/using-custom-rewrite-providers-with-url-rewrite-module
- http://archive.msdn.microsoft.com/rewriteextensibility
- http://forums.iis.net/t/1186281.aspx
- http://forums.iis.net/t/1188570.aspx/1
- http://www.iis.net/learn/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables
- http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#UsingServerVars
Hopefully this can help someone else out in the future.
Side note - the custom rewrite provider must target .NET 2.0, which is left out of the first link above.