ASP.NET restarts when a folder is created, renamed or deleted

This code appears to resolve the issue, when added to Application_Start() in Global.asax:

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[] { }); 

http://dotnetslackers.com/Community/blogs/haissam/archive/2008/11/12/disable-session-expiration-when-using-directory-delete.aspx

With these changes, I can create/modify/delete folders without causing the application to restart.

Not clear if this is the best solution — Don’t know if there will be unwanted side effects due to calling StopMonitoring.

Leave a Comment