简体   繁体   English

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

[英]Creating a Folder in C#, Applying Permissions, But access is still DENIED?

So I have this code below that creates a Directory and gives ASPNET permissions on the folder created. 因此,我在下面的代码中创建了一个目录,并为创建的文件夹提供了ASPNET权限。 But when I run The Webclient.Downloadfile method, it says the folder created is still access denied.. 但是当我运行Webclient.Downloadfile方法时,它说创建的文件夹仍然被拒绝访问。

Ive also just created a folder on C:/ and tried applying permissions my self and see what I get. Ive还在C:/上创建了一个文件夹,并尝试自行应用权限并查看得到的内容。 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. 这是Webclient.Download文件方法即时调用。
folderID is the the directory Exp: "C:\\hello" folderID是目录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. 附带说明:这是一个CONSOLE应用程序...它不是网页或Web服务。

Is folderID the file that the data should be downloaded to or the folder that you want it downloaded to? folderID是数据应该下载到的文件还是您要下载到的文件夹? It should be the file. 它应该是文件。

public void DownloadFile( Uri address, string fileName ) 公共无效DownloadFile(Uri地址,字符串fileName)

Parameters 参量

address Type: System.Uri The URI specified as a String, from which to download data. address类型:System.Uri指定为String的URI,可从该URI下载数据。

fileName Type: System.String The name of the local file that is to receive the data. fileName类型:System.String要接收数据的本地文件的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM