I have an asp.net web application that allows users to upload files to the "uploads" directory, which is in the same virtual directory as the web application. Each downloaded file goes into a temporary subdirectory named after the user session identifier. Once I am done with the files, I delete the temp temporary directory. The only problem is that when you delete a subdirectory, AppDomain gets recycled and kills all user sessions (using the inproc session state). The culprit seems to be FileChangesMonitor, which keeps track of changes in all subdirectories of the application.
The following code works fine in IIS 6.0 running on Windows Server 2003 to disable FileChangesMonitor for subdirectories, but for some reason it doesn't work on IIS 7.0 on Windows Server 2008:
System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object o = p.GetValue(null, null);
System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });
I found another solution that completely disables FileChangesMonitor here . But this is not an ideal solution, because I still want to control all the other files except the temp subdirectories in the "uploads" directory.
Why does this work in IIS 6.0 and not in IIS 7.0?
In IIS 7.0, can you specify auxiliary directories in a virtual folder to which you want to disable recycling?
Is there any other way to do this without using reflection?
source
share