1、参考 stackoverflow
http://stackoverflow.com/questions/2248825/asp-net-restarts-when-a-folder-is-created-renamed-or-deleted
http://dotnetslackers.com/Community/blogs/haissam/archive/2008/11/12/disable-session-expiration-when-using-directory-delete.aspx
的解释,这事asp.net 的自我回收机制,属于正常现象;解决方法有两中:
a、 需要删除的文件,不要放在根目录下,或者说工程目录下,避免触发回收机制
b、 新建Global.asax 在Application_Start() 中添加如下代码:
PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });
要添加 using System.Reflection;
别问我,代码是神马意思,我只是大自然的搬运工!!!