使用Directory.Delete(目录,true)时,它会将用户从网站中注销

人气:941 发布:2022-09-22 标签: html asp.net c# ASP.NET

问题描述

我已经搜索了谷歌的解决方案,但看起来这不是一个常见问题,所以我找不到答案。 我创建了一个网站在asp.net C#中使用登录系统 我有一个按钮,从我的解决方案中点击时删除指定的文件夹(我不能比这更清楚) 此文件夹包含由用户上传的文件,但在完成使用后我希望用户能够通过网站删除文件夹(无需进入解决方案) 我用来删除的代码是这个

I have searched google for a solution but it looks like this isn't a common issue so I can't find an answer. I created a website in asp.net C# with a login system I have a button that deletes the specified folder on click from my solution(I can't be more clear than this) This folder contains files that get uploaded by the user but when it is done being used I want the user to have the ability to delete the folder through the website(not needing to go into the solution) The code I use to do the delete is this

public Boolean deleteFolder(String directory, String FolderName)
    {
        directory = page.Server.MapPath(directory + "/" + FolderName);
        if (Directory.Exists(directory))
        {
            try
            {
                Directory.Delete(directory, true);
            }
            catch (IOException)
            {
                Thread.Sleep(1);
                Directory.Delete(directory, true);
            }
        }
        if (Directory.Exists(directory))
        {
            deleteRecuring(directory);
        }

        return false;
    }

//Deleting the files in the folder first
private void deleteRecuring(String directory)
    {
        try
        {
            string[] files = Directory.GetFiles(directory);
            string[] dirs = Directory.GetDirectories(directory);

            foreach (string file in files)
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
            }

            foreach (string dir in dirs)
            {
                deleteRecuring(dir);
            }

            Directory.Delete(directory, false);
        } 
        catch {}                
        if (File.Exists(directory))
        {
            Thread.Sleep(1);
            //deleteRecuring(directory);
        }
    }

我遇到的问题是,当我点击删除文件夹及其所有内容时,它会记录用户(曾登录过的用户)网站之外的网站。 我不确定为什么会发生这种情况,并希望有人可以查看我的代码,并指导我找到答案以及如何解决它 如果这有任何不清楚的地方,请告诉我还有什么我不知道所以我可以添加它。

The issue I have is that when I click to delete the folder and all of its contents it logs the user(who ever is logged into the website) out of the website. I am unsure why this is happening and hoping someone could look at my code and maybe guide me to the answer and how to fix it If this is by any means unclear, please tell me what else I am missing so I can add it in.

推荐答案

原因是ASP.NET引擎在应用程序文件夹下进行修改并对其进行监视时回收AppDomain。建议将使用App_Data。 或者通过以下链接解决方法忽略监控

138