How To Run Multiple .Net Website Versions Simultaneously

RSS
Modified on 2011/11/19 16:11 by Mark Categorized as dotNet, web
This entry describes how to seamlessly run multiple .Net websites simultanously in production, with a single version active for web users. Using this approach you can instantly switch between different versions, allowing for instant upgrade and rollback scenarios.

Problem Statement

Needing to run multiple versions of a website to allow for testing and instant upgrade and rollback while maintaining the appearance of running a single instance to the enduser.

Solution

Install website versions as a subdirectory under the website root and use a UrlRewrite rule to redirect requests to the currently active version.

Filesystem layout:
/root
  web.config (Rewrite rules are defined here)
  /v1
    web.config (version specific config)
  /v2
  ...
  /vn

Rewrite rule:
<configuration>
   <system.webServer>
      <rewrite>
         <rules>
            <rule name="rewrite to active website">
               <match url="^(.*)$" />
               <action type="Rewrite" url="v1/{R:0}" />
               <conditions>
                  <add input="{URL}" pattern="^/v[0-9]+?/.*" negate="true" />
                  <add input="{URL}" pattern="^/v[0-9]+$" negate="true" />
               </conditions>
            </rule>
         </rules>
      </rewrite>
   </system.webServer>
</configuration>

See also