简体   繁体   English

使用Web.Net.WebClient下载文件

[英]Using Web.Net.WebClient to download a file

FF I am beginner in the download files and directories with c# using Web.Net.WebClient . 我是使用Web.Net.WebClient使用c#下载文件和目录的初学者。 I tried this snippet to download a file: 我尝试了以下代码片段下载文件:

 Upload.Models.FichierModels fichier = new FichierModels();
 WebClient client = new WebClient();
 try
 {
  client.DownloadFile(new Uri(fichier.GetFichierUrlById(_id)), "fichier");
 }
 catch { }

but I got this exception: 但是我有这个例外:

Access to the path 'C: \\ \\ Program Files (x86) \\ \\ IIS Express \\ \\ file' is denied 拒绝访问路径“ C:\\\\ Program Files(x86)\\\\ IIS Express \\\\ file”

What is the cause of this exception? 此异常的原因是什么? How can I fix my code? 如何修复我的代码?

You will have to find out from the application pool for the website what is the identity it is running under. 您将必须从网站的应用程序池中找到其运行身份是什么。

By default this is Application Pool Identity. 默认情况下,这是应用程序池标识。

And then you will have to grant that the correct permissions. 然后,您必须授予该正确的权限。

Like Follows: 喜欢跟随:

SOLUTION

  1. Start > Administrative Tools > Internet Information Services (IIS) Manager 开始>管理工具> Internet信息服务(IIS)管理器

  2. Expand the machine node > expand Sites 展开计算机节点>展开站点

  3. Locate GFI MailArchiver virtual directory 找到GFI MailArchiver虚拟目录

  4. Right-click GFI MailArchiver virtual directory > Edit Permissions... 右键单击“ GFI MailArchiver”虚拟目录>“编辑权限...”。

    select Security tab 选择安全选项卡

  5. Add Domain Admins and Domain Users with Full Control Permissions 添加具有完全控制权限的域管理员和域用户

Referance: 全球化志愿服务青年:

http://kb.gfi.com/articles/Skynet_Article/Error-Access-to-path-C-Program-Files-X86-GIF-MailArchiver-ASPNET-profiles-username-is-denied-when-loading-web-UI http://kb.gfi.com/articles/Skynet_Article/Error-Access-to-path-C-Program-Files-X86-GIF-MailArchiver-ASPNET-profiles-username-is-denied-when-loading-web- UI

Hope Its Helpful. 希望对您有所帮助。

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

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