How IIS Handles Web.config Modifications at Runtime: Impact on Application Restarts and Configuration Reload Behavior


2 views

When you modify a Web.config file in a running IIS application, the Internet Information Services (IIS) runtime immediately detects this change through its file change notification system. The configuration system treats this as a significant modification that requires reevaluation of the application's settings.

IIS responds by restarting the application domain (AppDomain) hosting your web application. This behavior is by design and serves several purposes:

  1. Ensures configuration changes take effect immediately
  2. Prevents potential configuration inconsistencies
  3. Maintains application stability

The exact process follows this sequence:

1. File system watcher detects change
2. IIS verifies file integrity
3. Configuration system parses new XML
4. Application domain gracefully shuts down
5. New AppDomain spins up with fresh config

While not recommended for production, you can temporarily disable automatic restarts during development:

<system.web>
    <httpRuntime enableVersionHeader="false" />
    <compilation debug="true" />
</system.web>
<system.webServer>
    <asp enableAppDomainCrossAppRedirects="false" />
</system.webServer>

For frequently changing settings, consider these patterns:

  • External configuration files referenced via configSource
  • Custom configuration providers
  • Database-stored settings with caching

You can programmatically detect config changes:

protected void Application_Start()
{
    var config = WebConfigurationManager.OpenWebConfiguration("~");
    config.FileChanged += (sender, args) => 
    {
        // Handle change event
    };
}

Frequent Web.config modifications can cause:

Impact Severity
Session state loss High
Cache invalidation Medium
Connection pooling Medium

When you modify the Web.config file on a running IIS server, IIS automatically detects the change through its file change notification system. This triggers a configuration reload event, which may cause the application domain (AppDomain) to restart depending on the modified section.

Application Restart Triggers: IIS will recycle the AppDomain when you modify these configuration sections:


<system.web>
  <compilation />
  <httpRuntime />
  <pages />
</system.web>
<system.webServer>
  <modules />
  <handlers />
</system.webServer>

Non-Restarting Changes: These modifications won't trigger a restart:


<appSettings>
<connectionStrings>
<system.web>
  <customErrors />
</system.web>

To modify Web.config without triggering restarts:

Option 1: Use External Configuration Files


<appSettings file="externalSettings.config" />

Option 2: Implement Configuration API


// C# example using ConfigurationManager
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
config.AppSettings.Settings["MyKey"].Value = "NewValue";
config.Save(ConfigurationSaveMode.Modified);

You can track configuration changes using this event handler:


protected void Application_Start()
{
    System.Web.Configuration.WebConfigurationManager.
        OpenWebConfiguration("~").ConfigurationChanged += (sender, e) =>
    {
        // Handle configuration change
    };
}

Frequent Web.config edits can impact performance due to:

  • AppDomain recycling overhead
  • Session state loss (if using InProc)
  • Cache invalidation

For production environments, consider implementing a configuration caching layer or using database-backed settings for frequently-changing parameters.

  1. Minimize runtime edits in production
  2. Use configSource attribute for modular configuration
  3. Implement proper file change notifications
  4. Consider using Azure App Configuration for cloud deployments