Iis – Application Settings outside of web.config

iisweb.config

I need to keep the production app settings section outside of Web.config; I don't want keys and other secret information to be kept inside source code repository. However, if I edit the app settings with IIS Mananger it changes the Web.config, which will be overwritten at the next deployment.

How can I keep those settings outside of the Web.config that comes with the application on deployment? For example, this is somehow done by Azure Web Sites – the app settings you configure in the portal are not stored in Web.config – that can be confirmed by downloading the file via FTP. How is it done?

Best Answer

For the appSettings and connectionStrings nodes in web.config you can move these into separate files outside of web.config.

In your web.config you would have:

<appSettings configSource="appsettings.config"></appSettings>

and then a new file appsettings.config:

 <?xml version="1.0"?>
 <appSettings>
     <add key="foo" value="bar" /> 
 </appSettings>

Then you have to make sure that you don't deploy these new files and keep them different on the production server and your dev environment.

All my web.config files are excluded from my deployment process, if I need to change them, I do that on the stage or production sites.

Related Topic