Set Web.config to Debug and Release respectively.

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Requirements: to develop a asp.net application, often want to use a different configuration in the debug and release, and the web.config file is only a

Solution: you can write debug environment configuration in the web.config, and then write the unique release environment configuration in web.release.config. Common writing for example:

1 replace a property of a value of the node, using “ SetAttributes” connectionString” &ldquo conversion will change; value, only in the “ Match” locator to find properties for the “ name” &ldquo values; MyDB” when using the node “ connectionString&rdquo value;. Other properties without changing the values need not fill in.

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>

2 replacing the entire node, “ Replace” converting web.config file to replace the entire <customErrors> festival.   please note, as in the <system.web> node has only one customErrors Festival, so there is no need to use “ xdt:Locator” characteristics.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>

3 remove a property on a node, the use of RemoveAttributes. Delete the compilation node debug this property.

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

The above can be tested.

Summary: through the web.release.config or web.debug.config according to the specified format to find and replace the node content, can achieve web.config at different generation environment in different versions, convenient debug and release.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ricky at November 19, 2013 - 5:50 AM