在C#中创建文件夹,应用权限,但访问仍然被拒绝?
因此,我在下面的代码中创建了一个目录,并为所创建的文件夹提供了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.