.Net application development specialists
asp.net, c#, vb.net, html, javascript, jquery, html, xhtml, css, oop, design patterns, sql server, mvc and much more
contact: admin@paxium.co.uk

Paxium is the company owned by myself, Dave Amour and used for providing IT contract development services including


  • Application development - Desktop, Web, Services - with Classic ASP, Asp.net WebForms, Asp.net MVC, Asp.net Core
  • Html, Css, JavaScript, jQuery, React, C#, SQL Server, Ado.net, Entity Framework, NHibernate, TDD, WebApi, GIT, IIS
  • Database schema design, implementation & ETL activities
  • Website design and hosting including email hosting
  • Training - typically one to one sessions
  • Reverse Engineering and documentation of undocumented systems
  • Code Reviews
  • Performance Tuning
  • Located in Cannock, Staffordshire
Rugeley Chess Club Buying Butler Cuckooland Katmaid Pet Sitting Services Roland Garros 60 60 Golf cement Technical Conformity Goofy MaggieBears Vacc Track Find Your Smart Phone eBate Taylors Poultry Services Lafarge Rebates System Codemasters Grid Game eBate DOFF

Everything you wanted to know about Web.Config

Web.config files have become more and more complicated and their more subtle intracies are often left a mystery to many.

This article will aim to collate many interesting things about the web.config.  I am starting this qucikly and will just add to it when I can.

configSource

Using configSource to create a seperate file for configuration.

Typically you may have some appSettings in your web.config looking something like this: 

       <appSettings>
              <addkey="SiteName"value="MySite"/>
              <addkey="Username"value="MyUsername"/>
              <addkey="Password"value="MyPassword"/>
       </appSettings> 

Another option at your disposal though is to have your appSettings in a seperate file and point the appSettings node in the direction of that file.

So lets say we created a folder in the root of our web app and called it App_Config and in there we placed a file called AppSettings.config. We could point our appSettings node in our web.config file to our seperate AppSettings file in one of the following two ways. 

       <appSettings file="App_Config\AppSettings.config" />
       <appSettings configSource="App_Config\AppSettings.config" />


Now as far as I'm aware you only have the option of using "file" for the appSettings but you can use configSource for any of the sections.

Now there are two very interesting and useful things about these two methods.  Firstly if you use file then you can have name key values in your web.config file and in your seperate file and duplicate names in the seperate file will override those in the web.config.  If however you use configSource then you cannot place any name value pairs in the main web.config - they all have to in the seperate file.

Another interesting and useful feature is to do with application restarts.  Normally changes to a web.config file cause an application to restart.  This is by design.  The web.config is normally read when an app starts and then cached.  Any changes to the web.config will not take effect until the app restarts - hence the reason for web.config changes causing an app restart.  So don't make any web.config changes unless you want your app to restart!

It would I think be nice though if we could reconfigure a web app and have it change behaviour on the fly without restarting.  Restarting is obvioudly bad as you can lose sessions etc.  In fact many developers put configuration values not in the web.config but in a database maybe to avoid this restarting problem.

Now the really useful point to this is that if you use configSource then any changes you make to your seperate file will not cause a restart but will be read by the configuration readers in real time without any nasty restarting!

Using file on the other hand doesn't cause a reatart either but also doesn't have any config values reflected in code until a restart is made some other way.