There are several approaches that you can consider.
For a web role, you can distinguish between production and production by examining the host name in the URL of the incoming request. Recognizing the context from the host name, you can use different configuration values. Thus, you have two connection strings in your web.config, and you, for example, change the code to use the corresponding name based on the host name.
Instead, instead of exchanging VIPs through the portal, write a tool, such as the Powershell cmdlet, to do this and activate a configuration change while doing the actual exchange.
A VIP swap in itself is simply a reconfiguration of load balancing.
EDIT: Here is some code that I massaged from another application (I actually use this logic to distinguish between tenants in an application with multiple tenants, but the principle is the same).
public class DeploymentContextModule : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += OnBegin; } void OnBegin(object sender, EventArgs e) { var app = sender as HttpApplication; if (app != null) { var ctx = app.Context; if (ctx != null) { var req = ctx.Request; if (req != null) { var url = req.Url; var hostName = url.Host; if (!string.IsNullOrEmpty(hostName)) { ctx.Items["DeploymentContext"] = DeploymentContext.Find(hostName); } } } } } }
Note that you need to come up with an implementation of DeploymentContext.Find(hostname) to map the host name to some useful data. For the production slot, the host name will be associated with the cloud service. For an intermediate slot, it will be a guide (without a hyphen).
Configure it in web.config as follows:
<modules runAllManagedModulesForAllRequests="true"> <add name="DeploymentContextModule" type="MyNamespace.DeploymentContextModule, MyNamespace" preCondition="managedHandler" /> </modules>
In your application, you can use httpContext.Items["DeploymentContext"] to determine your deployment slot and accordingly read the correct configuration parameters.