Manage multiple web.config files for Azure MVC3 application

I have an ASP.NET MVC 3 application running on Azure. It also uses SQL Azure for the database.

I want to deploy this application in different instances (Testing, Demo, multiple Productions), and each instance needs its unique SQL database.

I know that with the new Azure Tools update, you can manage multiple service configurations. This is great and almost solves my problem. The only problem is with the SQL connection strings in the web.config files in the MVC part of the project.

I want exactly the same functionality as in the function of multiple service configurations, but for this for SQL connection strings.

Thanks for the help!

+6
source share
2 answers

. Clean configuration configurations should do the job. Like Azure Service Configurations, a separate Web.ConfigurationName.config file is created for each instance that you want to deploy to. Building a solution with the proper configuration (testing, demonstration, etc.) Will inject the correct instance configuration values ​​into the Web.config file.

+5
source

I usually maintain my SQL connection strings in ServiceDefinition files. * .cscfg. Thus, you get an additional advantage in the ability to edit them when starting instances, which is great for VIP swaps.

If you are testing out of the emulator on development machines, it is quite simple to write an abstraction over config:

class AzureConfig : IConfig { public string GetConnectionString(string name) { get { return RoleEnvironment.GetConfigurationSettingsValue(name); } } } class OnPremConfig : IConfig { public string GetConnectionString(string name) { get { return ConfigurationManager.ConnectionStrings[name].ConnectionString; } } } 

Then configure your IoC container to check RoleEnvironment.IsAvailable and return the appropriate type.

+3
source

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


All Articles