Modify Web Configuration file without restarting asp net worker process (aspnet_wp).

19 10 2008

Modify Web Configuration file without restarting asp net worker process (aspnet_wp).

No one in the world can say that web.config file will remain intact after the deployment. Modifications have to happen to some or the other parameters of the web configuration file like one has to add or remove key value pairs from appsettings section etc…

So what?
As soon as the webs configuration file is saved the aspnet_wp worker process of that particular web application gets restarted and all the current sessions and data are lost.

This can cause tremendous issues to an organization whose application needs to be up for 24*7.

To recover from such kind of scenario Microsoft has already provided a great tweak to handle this.

Following are some steps that need to be followed.
Step 1) Make a separate configuration file lets say for example appsettings.config with the following xml data.


<?xml version="1.0"?>
<appSettings>
  <clear/>
  <add key="Name" value="Dhaval"/>
  <add key="Surname" value="Upadhyaya"/>
</appSettings>

Step 2) Now in the original web.config file make your appSettings section look like below


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

You are done.

 
Place a debug point on the Application_Start event in global.asax file and check that changing appsettings.config does not restart the worker process.

Advertisements

Actions

Information

6 responses

24 01 2009
Martin

Great article!!, i will do this next monday in my work.

Thanks

5 04 2010
Jawad Khan

Unfortunately this doesn’t work. The new setting you are going to put in the newly creates appsettings file won’t take affect untill you restart the appdomain so yu are avoiding the automatic restart of the application but you losing the ability to have the new settings activates at same time so we are back to where we started.

10 04 2010
Dhaval Upadhyaya

Thats not correct. In the example depicted just go and place a button clicking on which it will fetch your data and write it to a page or lable just to check the value. Now start of with the application. Go and change the value in the external appsettings file and just click the button and you will get your answer.

15 03 2013
Rupen

Hi, Dhaval,

Just wanted to know, will it happen in IIS7 (or VS2010)? I tried placing a breakpoint in Application_Start event, ran the application. then change web.config to add new key and hit save but that didn’t bring me to my breakpoint in Application_start event.

23 03 2013
Dhaval Upadhyaya

It should. Try to refresh your page after you save.

17 06 2014
Rajesh

Its partially not working for me.
1.Work process is not restarting- Correct
2.Modified values are not reflecting even after I changing all my shared values/methods.

Do I need to make any changes in IIS?

Could you please share if you have any alternate thoughts?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: