C# 使用Web.Net.WebClient下载文件

C# 使用Web.Net.WebClient下载文件,c#,file,download,webclient,C#,File,Download,Webclient,我是c语言下载文件和目录的初学者,使用Web.Net.WebClient。 我尝试使用此代码段下载文件: Upload.Models.FichierModels fichier = new FichierModels(); WebClient client = new WebClient(); try { client.DownloadFile(new Uri(fichier.GetFichierUrlById(_id)), "fichier"); } catch { } 但我

我是c语言下载文件和目录的初学者,使用
Web.Net.WebClient
。 我尝试使用此代码段下载文件:

 Upload.Models.FichierModels fichier = new FichierModels();
 WebClient client = new WebClient();
 try
 {
  client.DownloadFile(new Uri(fichier.GetFichierUrlById(_id)), "fichier");
 }
 catch { }
但我有一个例外:

访问路径“C:\\Program Files(x86)\\IIS Express\\ 文件“”被拒绝


这个异常的原因是什么?如何修复我的代码?

您必须从网站的应用程序池中找出它运行的身份

默认情况下,这是应用程序池标识

然后你必须授予它正确的权限

具体如下:

解决方案

  • 开始>管理工具>Internet信息服务(IIS) 经理

  • 展开计算机节点>展开站点

  • 找到GFI MailArchiver虚拟目录

  • 右键单击GFI MailArchiver虚拟目录>编辑权限

    选择安全选项卡

  • 添加具有完全控制权限的域管理员和域用户

  • 参考:


    希望对您有所帮助。

    我找不到GFI MailArchiver虚拟目录。iselected sites-->默认网站如pic中所示