How to prevent ASP.NET application from restarting when changing web.config?

I have an ASP.NET runtime using the ApplicationHost.CreateApplicationHost method. When I change web.config while the application is running, I see a lot of the first chance of a ThreadAbortException . This is right before my application crashes. I assume this is because the runtime detected configuration changes and wants to restart.

This is actually not a supported scenario, so I would prefer to just turn off automatic reloading.

Does anyone know how to do this?

+27
web-config iis
Mar 05 '09 at 6:58
source share
5 answers

As far as I know, there is no way to disable this behavior, changes to webconfig cause the application to restart.

Update: this is actually possible, there are a number of methods well documented as explained in this answer *

Original answer:

There is a similar question here for other links only. I found additional information that might be helpful.

Configuration changes Cause a Rebooting the application domain
Changes to the configuration settings in the Web.config files indirectly cause the domain to be used to reboot. This behavior occurs by design. You can optionally use the configSource attribute to reference external configuration files that do not cause a reboot when the change is made. For more information, see configSource in General Attributes Inherited by section elements.

From This MSDN Article

* Disclaimer: I wrote a different answer and, as a rule, did not become self-observation, but I think it is relevant enough for reference here, because 8 years after this message it is really quite different: the solution is very simple by clicking on the IIS interface, and workarounds exist after ASP.NET 1.0.

+25
Mar 05 '09 at 7:04
source share

I ran into an even more serious problem on the same lines - changes to any file or subfolder in the AppDomain base directory will disable the hosting environment. This is a pretty big problem for our application, since we are launching the WPF interface in the same AppDomain, and we cannot restart it without being invalid for the user.

I really wanted to avoid having to run a separate AppDomain for the web part of the application, so I did something with Reflector. I found that the culprit was the inner class FileChangesMonitor .

So, I wrote a terrible terrible hack to solve the problem. I thought I would post it here as a potential solution for anyone who has the same problem. You just need to call HttpInternals.StopFileMonitoring() to disable shutdown when changing the file / folder.

 internal static class HttpInternals { private static readonly FieldInfo s_TheRuntime = typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static); private static readonly FieldInfo s_FileChangesMonitor = typeof(HttpRuntime).GetField("_fcm", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly MethodInfo s_FileChangesMonitorStop = s_FileChangesMonitor.FieldType.GetMethod("Stop", BindingFlags.NonPublic | BindingFlags.Instance); private static object HttpRuntime { get { return s_TheRuntime.GetValue(null); } } private static object FileChangesMonitor { get { return s_FileChangesMonitor.GetValue(HttpRuntime); } } public static void StopFileMonitoring() { s_FileChangesMonitorStop.Invoke(FileChangesMonitor, null); } } 
+19
Mar 10 '09 at 12:16
source share

Actually, the first two answers are incorrect. It is possible and quite easy to prevent this recirculation, and this feature was available, at least with IIS6.

Method 1 (in the system system)

Change the DWORD parameter for the HKLM\SOFTWARE\Wow6432Node\Microsoft\ASP.NET\FCNMode to 1 , which will turn off all file change notifications.

Do not confuse the location: Wow6432Node in this case does not affect the bit rate of your web application.

Method 2 (.NET 4.5+)

If you are using .NET 4.5, now you can disable it at the site level , just use the following in web.config :

 <httpRuntime fcnMode="Disabled"/> 

Method 3 (IIS6 +)

Finally, and also (at least) around with IIS6 there is a parameter called DisallowRotationOnConfigChange , as an option only for the application pool (at least this is what I think the text in MSDN is trying to say, but I have not tested it). Set it to true , and changes to the configuration of the application pool will not lead to immediate processing.

This last parameter can also be set from the advanced settings of the application pool:

Disable Recycling for Configuration Change

Method 4 (ASP.NET 1.0 and 1.1)

For (old) websites using ASP.NET 1.0 or 1.1 there is a confirmed error that can lead to fast and repeated repeats in the change file. The workaround at that time was similar to what MartinHN suggested in the main question, namely the following in web.config :

 <compilation debug="false" defaultLanguage="vb" numRecompilesBeforeAppRestart="5000"> 

This does not disable recirculation, but it only happens after 5000 recompilations. Whether this number is useful depends on the size of your application. Microsoft does not clearly say what recompilation is. However, the default value is 15.

Aside: regardless of the version of .NET or Windows, we find that when an application is launched from a shared resource and used in a load-balanced environment, the site is constantly being redesigned. The only way to solve this problem is to add the FNCMode parameter to the registry (but now there are smaller options).

+13
Jul 17 '15 at 7:04
source share

The solution will add the following element to the web.config section:

 <httpRuntime waitChangeNotification="315360000" maxWaitChangeNotification="315360000" /> 
+9
Aug 24 '09 at 9:54
source share

As jfburdet mentioned, the solution should use waitChangeNotification and maxWaitChangeNotification.

However, you should know that they do not work on IIS 7 if ASP.NET is running in mixed mode: http://forums.iis.net/t/1149344.aspx

0
Dec 10 '09 at 9:20
source share



All Articles