1.首先添加一个类StopAppDomainRestartOnFolderDelete.cs
代码如下:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Reflection; 6 namespace MyWebsite 7 { 8 public class StopAppDomainRestartOnFolderDeleteModule : IHttpModule 9 { 10 public void Init(HttpApplication context) 11 { 12 PropertyInfo p = typeof(HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); 13 object o = p.GetValue(null, null); 14 FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase); 15 object monitor = f.GetValue(o); 16 MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic); 17 m.Invoke(monitor, new object[] { }); 18 19 } 20 public void Dispose() { } 21 } 22 }
2.修改web.config文件
在<httpModules>节点中添加 <add name="stopAppDomainRestartOnFolderDelete" type="MyWebsite.StopAppDomainRestartOnFolderDeleteModule" />
。stopAppDomainRestartOnFolderDelete 自定义名称 建议与类名相同
。MyWebsite.StopAppDomainRestartOnFolderDeleteModule StopAppDomainRestartOnFolderDelete.cs 命名空间.类名称