在C#中创建文件夹,应用权限,但访问仍然被拒绝?

发布于 2024-08-17 19:46:40 字数 969 浏览 5 评论 0原文

因此,我在下面的代码中创建了一个目录,并为所创建的文件夹提供了 ASPNET 权限。但是当我运行 Webclient.Downloadfile 方法时,它说创建的文件夹仍然被拒绝访问。

我还刚刚在 C:/ 上创建了一个文件夹,并尝试自己应用权限,看看会得到什么。但我仍然被拒绝访问。

有人可以帮忙吗?

 DirectoryInfo di = Directory.CreateDirectory(path);
                    System.Security.AccessControl.DirectorySecurity dSec = di.GetAccessControl();
                    dSec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"LV38PCE00081461\ASPNET", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
                    di.SetAccessControl(dSec);

这是我调用的 Webclient.Download File 方法。
folderID 是目录 Exp: "C:\hello"

WebClient webClient = new WebClient();
webClient.DownloadFile(new Uri(reader.Value), folderID);
Console.WriteLine(folderID + " File Downloaded");

上面的方法导致访问被拒绝。

附注:这是一个 CONSOLE 应用程序...它不是网页或 Web 服务。

So I have this code below that creates a Directory and gives ASPNET permissions on the folder created. But when I run The Webclient.Downloadfile method, it says the folder created is still access denied..

Ive also just created a folder on C:/ and tried applying permissions my self and see what I get. But I still get access denied.

Can anyone help?

 DirectoryInfo di = Directory.CreateDirectory(path);
                    System.Security.AccessControl.DirectorySecurity dSec = di.GetAccessControl();
                    dSec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"LV38PCE00081461\ASPNET", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
                    di.SetAccessControl(dSec);

Here is the Webclient.Download File Method im calling.
folderID is the the directory Exp: "C:\hello"

WebClient webClient = new WebClient();
webClient.DownloadFile(new Uri(reader.Value), folderID);
Console.WriteLine(folderID + " File Downloaded");

This Method above is what gives the Access denied.

On a Side note: This is a CONSOLE application... Its not a webpage or a web service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永言不败 2024-08-24 19:46:40

folderID 是数据应下载到的文件还是您希望将其下载到的文件夹?应该是文件。

公共无效下载文件(
URI 地址,
字符串文件名
)

参数

地址
类型:System.Uri
指定为字符串的 URI,从中下载数据。

文件名
类型:System.String
要接收数据的本地文件的名称。

Is folderID the file that the data should be downloaded to or the folder that you want it downloaded to? It should be the file.

public void DownloadFile(
Uri address,
string fileName
)

Parameters

address
Type: System.Uri
The URI specified as a String, from which to download data.

fileName
Type: System.String
The name of the local file that is to receive the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文