I'm curious how the web.config is loaded into a application, is any reference to values in the web.config actually parsing the web.config file, or upon application start does it load the values into a singleton or something?
This came to my mind as I wanted to check for a value in the web.config on a per request basis in the global.asax.cs:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if( ConfigurationManager.AppSettings["abc"] != null)
{
}
}
When an application first gets a request, the config file(s) get parsed and its settings loaded. These settings are then cached, so that any subsequent call doesn't require re-parsing the config file(s). That is why when a config file is changed, the application restarts and gets recompiled again.
http://msdn.microsoft.com/en-us/library/ms178685.aspx#calculating_configuration_settings_at_runtime
The configuration gets deserialized during application startup into the corresponding ConfigurationSection
types.
These are normally implemented with read only properties, so they can be indeed used in a singleton.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With