Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Directory from ASP.NET application returns to new session

I'm deleting a directory from within an ASP.NET application. The deletion goes fine, but when I return from it all my session data from before the delete is lost.
It doesn't matter whether I use:

                if (Directory.Exists(folderPath))
                    Directory.Delete(folderPath, true);

Or:

                System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(folderPath);
                if (d.Exists)
                    d.Delete(true);

In both cases I lose my session data.

Has anyone run into this problem?

like image 681
Lea Cohen Avatar asked Mar 12 '09 13:03

Lea Cohen


3 Answers

If you are deleting a subdirectory within your application, your app domain will restart. This removes all session data. To alleviate this issue, only add/remove directories outside your application home directory.

like image 101
Beep beep Avatar answered Oct 15 '22 14:10

Beep beep


Is the directory within the same application? Then deleting it will cause an AppDomain restart, which will result in loss of session state.

like image 23
John Saunders Avatar answered Oct 15 '22 13:10

John Saunders


Yes! Deleting a directory IIS is serving, causes a reset (or something). I have had this problem, I redesigned the app to not delete directories.

Shame on the -1 for the question, this is a real problem. +1 for someone with a fix.

like image 20
tarn Avatar answered Oct 15 '22 13:10

tarn