By default, all the Asp.Net web applications come up with two default configurations debug and release. These configurations are maintained in Web.Debug.config & Web.Release.config files. Configurations are not used when we are developing the application, they are used when we are publishing the application.
First Let us see how to add a new configuration (UAT) and later publishing the application with the new configuration.
Adding new configuration
Adding Web.UAT.config file
Let us configure connectionstring and appsetting for different environments
We need to add xtd:Transform & xtd:Locator attributes as shown above. These attributes are used to identify the settings that needs to be reflected in the web.config file on publishing.
Now let us see how to publish an application with UAT configuration. Publishing is the process of generating output files/binaries/build which will be hosted on the IIS server. Visual Studio provides a wizard for publishing the application.
Below screenshots explain how to publish an application with the desired configuration
Let us explore the published output in “C:/Test” folder
Let us see what are the configurations that got reflected in the Web.cofing file inside “C:/Test” folder.
Since we have selected UAT environment while publishing the app, the corresponding connectionstring and appsetting got reflected in the published output web.config file.
Conclusion:
Configurations are not used when we are developing the application, they are used when we are publishing the application. Even though you select UAT configuration from toolbar and run the application as shown below, it is going to take the values from Web.config rather than taking it from UAT.web.config file.
Configurations help us maintain different settings for different environments without making manual changes.
Sample Code
https://github.com/KishoreIthadi/BlogSamples/tree/master/MVC/MVC_Configurations
Happy Coding 🙂
Please leave a comment below, and let me know what you think!