WebClient下载 - “访问路径'c:\\ windows \\ system32 \\ inetsrv \\ MyPrintManager.exe'被拒绝”

时间:2013-05-10 14:58:18

标签: c# iis download webclient

我正在尝试从本地计算机上的另一个IIS站点下载文件。我的主网站试图从另一个公共站点下载,其中包含一些用户可以下载的文件。

[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);
}

出于某种原因,它试图从C:\windows\system32\inetsrv\MyPrintManager.exe下载文件?有谁知道如何避免它指向该目录?我是否需要修改我的代码或IIS配置?

此网站的虚拟目录是我的C:驱动器上的文件夹,我实际要下载的文件位于该目录中。

2 个答案:

答案 0 :(得分:4)

不,它正在尝试将文件保存到 C:\windows\system32\inetsrv\MyPrintManager.exe

那是因为C:\windows\system32\inetsrv是您的流程的工作目录,而您刚刚给出了相对文件名。

指定一个绝对文件名,用于准确说明文件的存储位置,应该没问题。

答案 1 :(得分:-1)

WebClient web = new WebClient();
string url = "http://.../FILENAME.jpg";
web.DownloadFile(new Uri(url), "C:/FILENAME.jpg");