Delete Directory from ASP.NET application returns

2019-03-27 09:16发布

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?

3条回答
家丑人穷心不美
2楼-- · 2019-03-27 09:39

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.

查看更多
在下西门庆
3楼-- · 2019-03-27 09:45

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.

查看更多
Explosion°爆炸
4楼-- · 2019-03-27 09:59

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

查看更多
登录 后发表回答