Asked by:
Delete directory kills session

Question
-
User-2037283231 posted
Hi,
I've written a web user control that deletes a directory from disk. I always know the directory is empty.The directory deletes fine, however it always kills the user session. Why might this be?
I've tried the following two methods to delete and both do the same:
My.Computer.FileSystem.DeleteDirectory(Path.Combine(_rootDirectory, _directoryID), FileIO.DeleteDirectoryOption.ThrowIfDirectoryNonEmpty)
And:
Directory.Delete(Path.Combine(_rootDirectory, _directoryID))
The code is in a try/catch block and no exception is being thrown.
Thanks for your help,
Tom
Saturday, February 25, 2006 7:53 AM
All replies
-
User2032526919 posted
Hi,
are you using ASP.NET 2.0? If yes, that's because deleting also non-application directory causes AppDomain restart. More information on here:
http://aspadvice.com/blogs/joteke/archive/2006/02/22/15299.aspx
http://weblogs.asp.net/owscott/archive/2006/02/21/438678.aspxOf course, one way to prevent this is to use out-of-process sessions.
Sunday, February 26, 2006 10:10 AM -
User-2037283231 posted
Thanks for your reply. It does seem that .NET 2.0 is very twitchy about appdomain restarts and the slightest change will cause one. I've moved it to an out-of-process session and it's fixed the problem... bigger fish to fry for now so it will do for the time being :)Sunday, February 26, 2006 10:50 AM -
User-668983782 posted
http://blogs.msdn.com/toddca/archive/2005/12/01/499144.aspxWednesday, March 8, 2006 10:18 AM -
User-835399560 posted
Could simply creating a virtual directory within the same application pointing to a folder outside of your web sites app domain accomplish the same thing as using the linkd tool?
Wednesday, April 19, 2006 2:25 PM -
User1045444031 posted
I've been looking through a few of these and no one seems to have found a solution that they like or is easily doable, so I will post the one that we came up with.
We have a program that deletes files that were uploaded and then deletes the directory that they were in. We delete the files like normal and then just saved the path to the directory to be deleted to a file called delete.txt that just houses the paths of directories to delete. Then when the user clicks log out we have some code that reads in the strings of directories to be deleted from delete.tx and deletes them.
If you guys want I can post some code as example.
Friday, July 14, 2006 3:27 PM -
User312496708 posted
Deleting a directory in asp.net is tricky. Afetr you delete a directory the application will restart and u will looase all ur session dat if u are using in-proc session. Here is a link explaining that
<a href= http://vikramlakhotia.com/Post.aspx?postID=6>a href= http://vikramlakhotia.com/Post.aspx?postID=6</a>Friday, August 11, 2006 4:46 AM -
User-357437097 posted
Hi,
this works, try it.
Carlo
http://support.microsoft.com/kb/911272/en-us
Registry information
<script type=text/javascript>loadTOCNode(3, 'resolution');</script> To enable this hotfix, you must add the following DWORD value at the following registry key:
HKLM\Software\Microsoft\ASP.NET\FCNModeThe following table lists possible values for the FCNMode DWORD value and the behavior that is associated with each value.
Value Behavior Does not exist This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory. 0 or greater than 2 This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory. 1 The application will disable File Change Notifications (FCNs). [:)] 2 The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory. Thursday, March 1, 2007 4:59 AM -
User-897749260 posted
i am try this
Registry information
loadTOCNode(3, 'resolution'); To enable this hotfix, you must add the following DWORD value at the following registry key:
HKLM\Software\Microsoft\ASP.NET\FCNModeThe following table lists possible values for the FCNMode DWORD value and the behavior that is associated with each value.
Value Behavior Does not exist This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory. 0 or greater than 2 This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory. 1 The application will disable File Change Notifications (FCNs). 2 The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory. Thursday, June 21, 2007 8:37 AM -
User-1268398592 posted
This happens because you are probably deleting files or directories......<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>Deleting a directory in asp.net is tricky. After you delete a directory the application will restart and you will loose all your session variables if you are using in-proc session.<o:p></o:p>I had the same problem and after searching the web, I found the following solution.<o:p></o:p>The following code<o:p></o:p> Put the following code in the Application_Start of your Global.asax<o:p></o:p>//FIX disable AppDomain restart when deleting subdirectory//Monitoring of Bin, App_Themes and other folders will still be operational, so updated DLLs will still auto deploy.System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor" <script><!-- D(["mb","\u003c/font\>\u003cfont size\u003d\"2\"\>, System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.NonPublic | System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.Public | System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.Static);\u003c/font\>\u003cfont size\u003d\"2\"\> \u003cp\>\u003c/p\>\u003c/font\>\u003cfont color\u003d\"#0000ff\" size\u003d\"2\"\>object\u003c/font\>\u003cfont size\u003d\"2\"\> o \u003d p.GetValue(\u003c/font\>\u003cfont color\u003d\"#0000ff\" size\u003d\"2\"\>null\u003c/font\>\u003cfont size\u003d\"2\"\>, \u003c/font\>\u003cfont color\u003d\"#0000ff\" size\u003d\"2\"\>null\u003c/font\>\u003cfont size\u003d\"2\"\>);System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>FieldInfo\u003c/font\>\u003cfont size\u003d\"2\"\> f \u003d o.GetType().GetField(\u003c/font\>\u003cfont color\u003d\"#a31515\" size\u003d\"2\"\>"_dirMonSubdirs"\u003c/font\>\u003cfont size\u003d\"2\"\>, System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.Instance | System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.NonPublic | System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.IgnoreCase);\u003c/font\>\u003cfont size\u003d\"2\"\> \u003cp\>\u003c/p\>\u003c/font\>\u003cfont color\u003d\"#0000ff\" size\u003d\"2\"\>object\u003c/font\>\u003cfont size\u003d\"2\"\> monitor \u003d f.GetValue(o);System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>MethodInfo\u003c/font\>\u003cfont size\u003d\"2\"\> m \u003d monitor.GetType().GetMethod(\u003c/font\>\u003cfont color\u003d\"#a31515\" size\u003d\"2\"\>"StopMonitoring"\u003c/font\>\u003cfont size\u003d\"2\"\>, System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.Instance | System.Reflection.\u003c/font\>\u003cfont color\u003d\"#2b91af\" size\u003d\"2\"\>BindingFlags\u003c/font\>\u003cfont size\u003d\"2\"\>.NonPublic);\u003c/font\>\u003cfont size\u003d\"2\"\> \u003cp\>m.Invoke(monitor, \u003c/p\>\u003c/font\>\u003cfont color\u003d\"#0000ff\" size\u003d\"2\"\>new\u003c/font\>\u003cfont size\u003d\"2\"\> \u003c/font\>\u003cfont color\u003d\"#0000ff\" size\u003d\"2\"\>object\u003c/font\>\u003cfont size\u003d\"2\"\>[] { });\u003c/font\>\n \u003c/div\>\u003c/div\>\u003cp\>\n You were sent this email because you opted to receive email\n notifications when someone responded to this thread.\n \u003cbr\>\u003cbr\>\n To unsubscribe, either:\n \u003col\>\u003cli\>\n Visit the above \u003ca href\u003d\"http://forums.asp.net/p/1097290/1822046.aspx#1822046\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\"\>",1] ); //--></script> , 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[] { });
Wednesday, July 25, 2007 3:50 AM -
User-1268398592 posted
This happens because you are probably deleting files or directories in the appdomain......Deleting a directory in asp.net is tricky. After you delete a directory the application will restart and you will loose all your session variables if you are using in-proc session.I had the same problem and after searching the web, I found the following solution.Put the following code in the Application_Start of your Global.asax:
//FIX disable AppDomain restart when deleting subdirectory
//This code will turn off monitoring from the root website directory.
//Monitoring of Bin, App_Themes and other folders will still be operational, so updated DLLs will still auto deploy.
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[] { });
Wednesday, July 25, 2007 3:54 AM -
User-412771404 posted
Any idea, how can I turn off monitoring on a specific folder? I.e. we have an 'uploads' folder, in that folder i want to turn off monitoring, i don't want to turn off monitoring on the entire site..
Thursday, September 6, 2007 3:10 PM -
User312496708 posted
I dont think that is possible. The monitoring cannot be stopped
Friday, September 7, 2007 4:04 AM -
User-1268398592 posted
I think vik2000in is right.....It is possible for mutiple dirs (like I showed above) but you do not have the choice of selecting just one.
Friday, September 7, 2007 4:47 AM -
User-412771404 posted
Well my new idea is to create my folder that i want to delete outside of the application root.
By the way, if i turn off directory monitoring, how would I force a recompile on the site? (Since it wouldn't notice any changes)
SameerFriday, September 7, 2007 9:01 AM