Windows Azure VIP Swap, how to handle custom web.config values?

It’s easy to publish a new deployment in the Cloud Service staging or workspace environment, but I would like to use the VIP package exchange (swap deployment and staging deployment) more often. In my case, I have different web.config values ​​for each environment. For example, when setting up my web.config, it might be:

<appSettings> <add key="ConnectionStringName" value="StagingConnectionString" /> <add key="WCFServiceUrl" value="http://somelongGUID.cloudapp.net/" /> </appSettings> 

... and at Production I would:

 <appSettings> <add key="ConnectionStringName" value="ProductionConnectionString" /> <add key="WCFServiceUrl" value="http://prodservice.cloudapp.net/" /> </appSettings> 

When published to Staging or Production, web.config is converted using the correct values ​​based on Debug or Release. But when it comes to VIP Swap on the Windows Azure portal, I have to run a swap, then delete all instances and manually change these values ​​(which is definitely not suitable for this).

What can be done to better cope with this situation? Or is there a better and more flexible solution for handling these custom configuration values ​​than for using them in web.config (especially in this case)?

Thanks in advance.

+4
source share
4 answers

Using VIP swap is considered the “standard” way to promote production staging as web and workers. It achieves this swap by changing the routing of Azure, pointing the production URL to the instance of the intermediate role and pointing the URL of the intermediate to the instance of the production role.

Internally, the roles are not aware of this change: this happens exclusively externally for the hosting process.

If you want to use VIP swaps in this way, you should consider changing the application so that you don’t know about its host environment, or that it reads information from its host when it needs it.


The way to create and install in Azure, the packages must be the same: both configurations in real time. This feature is designed for high availability deployments; he is not responsible for the types of testing that will be implied when a role is called by another service, depending on whether this is an intermediate deployment or not.

You better use a separate role for testing; in order to verify that your deployment was successful before you select the switch with the current production deployment.

+5
source

VIP swap, as the name implies, is an exchange of a virtual IP connection. Therefore, I think this is a simple change of DNS pointers to the IP address of the device, so I don’t think that a configuration conversion could happen. Deployment deployment should be consistent in every sense with production deployment.

If you want to test the deployment with a different configuration, it’s better to create a new service in Azure and place the solution with the scene settings there. After satisfaction, make a new deployment to the workspace slot. Make quick smoke and swap.

+2
source

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.

+1
source

It might be worth taking a look at the CloudConfigurationManager class, which looks at csfg or web.config configuration settings. This will allow you to define your settings in the ServiceConfiguration.Cloud.cscfg file and edit them from the Azure portal before changing your VIPs.

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.cloudconfigurationmanager.aspx

0
source

Source: https://habr.com/ru/post/1494750/


All Articles