How to Configure a Web Application Before Deployment?

When an ASP.NET application is deployed on a Web server, there are some settings in the deployed application’s Web.config file, which need to be different from the Web.config file in the development environment. For example, you might want to disable debug options and change connection strings so that they point to different databases. These group of settings need to be set up in the Web.config transformation file.

A transformation file refers to an XML file that allows you to specify how the Web.config file should be changed when it is deployed. The transformation actions can be specified in the Web.config file by using XML attributes. A transform file is associated with a build configuration. By default, Visual Studio creates Debug and Release build configurations by the name, Web.debug.config and Web.release.config. However, you can also create custom build configurations.

The Web.release.config file stores changes that Microsoft Visual Studio applies to the Web.config file, when you compile the application in the Release mode.

The Web.debug.config file stores changes that Microsoft Visual Studio applies to the Web.config file, when you compile the application in the Debug mode.

Before you publish the application using release configuration, you need to remove the debug attribute from the <compilation> element in the Web.config file. For this, the following markup is included in the Web.release.config file:

<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)"/>
</system.web>

In the preceding markup, the xdt: Transform attribute is used to remove the debug attribute from the Web.config file.

You can also add additional elements to the transformed Web.config file. For example, the following code snippet shows how to insert a new connection string setting in the transformed Web.config file:

<connectionStrings>
<add name="DemoConnStr" connectionString="Data Source=|DataDirectory|demo.mdf"
providerName="System.Data.SqlServerCe.4.0" xdt:Transform="Insert"/>
</connectionStrings>

In the preceding code snippet the value, Insert, has been used for the xdt: Transform attribute to insert a new connection string in the transformed Web.config file.

SHARE THIS

Get A Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.