If you cannot postpone restarting AppDomain, you can disable it.
There is a Change Change File (FCN) behavior that can be disabled.
Registry
Initially, this is an entry in the DWORD registry in HKLM\Software\Microsoft\ASP.NET\FCNMode , setting it to 1 to disable it .
Code (hack) before .NET Framework 4.0
This hack can work with frameworks 2.0-3.5 and 4.0.
//Disable AppDomain restart on file change System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); object fcm = p.GetValue(null, null); System.Reflection.MethodInfo m = fcm.GetType().GetMethod("Stop", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); m.Invoke(fcm, new object[] { });
Put it in your Global.asax Application_Start . See here .
If you want to disable monitoring for specific paths or files, you can use the StopMonitoringFile or StopMonitoringPath from FileChangesMonitor . However, the Bin directory is a special directory and may be immune to these two methods.
At least you can play in the _dirMonSpecialDirs field and call StopMonitoring() in your Bin directory.
.NET Framework 4.5
In the .NET Framework 4.5, the HttpRuntimeSection.FcnMode property exists . There is not much documentation, but you can use <httpRuntime fcnMode="Disabled"/> .
source share