Adding transformations to your web.conifg

Transformations in asp.net is an easy way to automatically set your configurations in different environments. An example of this would be when we want our connection strings, usernames, passwords,  proxies, etc. to be different in our development environment from our production environment.  Since the web.config file is written in xml, we use XML Document-Transform(xdt) to make the transformations.

In your VisualStudio project every web.config has a Web.Debug.config  and Web.Release.config. If you have never used transformations before, you probably don’t know what these files are for.

Web.Config:

Web.Release.Config:

Changes this transformation file does:

  • It will match the key SPath and change the value to D:\Program File\path.txt.
  • It will replace the  customErrors tag with mode="On".

If you try to use xdt:Transform="Replace" and your web.config file does not contain what you are trying to replace, it will be added.

Check out the Microsoft documentation for more examples.

Bookmark and Share

Leave a Reply

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