Could you tell me what exactly happens when we edit the Web.config (at runtime) on a IIS server?

The ASP.NET AppDomain is restarted whenever you 'touch' web.config. It's possible to turn off the File Change Notification (FCN) for a folder, but it's usually not the best bet if you can help it. If you do turn it off, it just means that you need to manually recycle the app pool for changes to take effect.

Prior to IIS7, only ASP.NET changes would cause the AppDomain recycle, but with IIS7 and many of the settings living in web.config, this is a more common issue. i.e. changing a default doc in IIS 7 Manager will cause that AppDomain recycle now.

Ideally you just need to keep your change rate down, or sometimes apply the change to applicationHost.config (which doesn't cause the AppDomain recycle) rather than web.config.


The application that uses the web.config will restart when you change it, there's more info here:

http://msdn.microsoft.com/en-us/library/ms178473.aspx

I don't know of any way to prevent this from happening (and I'm not sure why you'd want to - perhaps you can provide some more details of what you're trying to achieve).


FYI - In ASP.NET 2.0 you can use the built in Health Monitoring Events to log application restarts along with the reason for the restart. This will enable you to clearly document when and how often it occurs. This is accomplished by editing the master web.config for the machine.

For more information:

http://blogs.msdn.com/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx