[英]WebClient Download - “Access to the path 'c:\\windows\\system32\\inetsrv\\MyPrintManager.exe' is denied”
I am attempting to download a file from another IIS site on my local machine. 我正在尝试从本地计算机上的另一个IIS站点下载文件。 I have my main website that is trying to download from another public site that contains a few files that the user will be able to download.
我的主要网站正在尝试从另一个包含一些文件的公共站点下载,用户可以下载这些文件。
[HttpGet]
public ActionResult DownloadMyPrintManagerInstaller()
{
bool success;
try
{
using (var client = new WebClient())
{
client.DownloadFile(new Uri("http://localhost:182//MyPrintInstaller.exe"), "MyPrintManager.exe");
}
success = true;
}
catch (Exception)
{
success = false;
}
return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}
For some reason, it is attempting to download the file from C:\\windows\\system32\\inetsrv\\MyPrintManager.exe
? 由于某些原因,它正尝试从
C:\\windows\\system32\\inetsrv\\MyPrintManager.exe
下载文件? Does anyone know how I can avoid it from pointing to that directory? 有谁知道如何避免它指向该目录? Do I need to modify my code or my IIS configuration?
我是否需要修改代码或IIS配置?
My virtual directory for this site is a folder sitting on my C: drive, and the file I actually want to download is in that directory. 我在该站点的虚拟目录是一个位于C:驱动器上的文件夹,而我实际要下载的文件在该目录中。
No, it's attempting to save the file to C:\\windows\\system32\\inetsrv\\MyPrintManager.exe
. 不,它正在尝试将文件保存到
C:\\windows\\system32\\inetsrv\\MyPrintManager.exe
。
That's because C:\\windows\\system32\\inetsrv
is the working directory for your process, and you've just given a relative filename. 这是因为
C:\\windows\\system32\\inetsrv
是您的进程的工作目录,并且您刚刚指定了相对文件名。
Specify an absolute filename which says exactly where you want the file to be stored, and it should be fine. 指定一个绝对的文件名,该文件名将准确说明要存储文件的位置,应该没问题。
WebClient web = new WebClient();
string url = "http://.../FILENAME.jpg";
web.DownloadFile(new Uri(url), "C:/FILENAME.jpg");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.