Friday, May 26, 2006

How-To: Split web.config sections into different files.

with my spin of automation I figured out that in our Build-Process we have to change some settings depends on the environment [development, testing, staging, life (we get there soon :-) )].

While each environment has its own connection strings and app-settings section we decided to split them from the web.config file and put them into different files. Well i didn't thought that this is possible, but MS have thought about it :-) Thanks!

<connectionStrings configSource="YourFileName1.xml"/>
<appSettings configSource="YourFileName2.xml"/>

Note: it has to be an XML file, correct me if I'm wrong but with anything else it worked.

great we have now own files which we can just copy after the deployment but ... here comes the clue behind it, if you do that you should also do the following thing to protect your files:


  <location path="YourFileName1.xml">
   <system.web>
    <authorization>
     <deny users="*"/>
    </authorization>
   </system.web>
  </location>

  <location path="YourFileName2.xml">
   <system.web>
    <authorization>
     <deny users="*"/>
    </authorization>
   </system.web>
  </location>

without to do that everybody else access your file's and can potentially harm your application - keep attention about it.

1 comment:

Anonymous said...

use .config files instead of .xml

nobody can access those.

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge