WebClient Download - “Access to the path 'c:\\windows\\system32\\inetsrv\\MyPrintManager.exe' is denied”

蓝咒 提交于 2019-12-04 06:24:19

问题


I am attempting to download a file from another IIS site on my local machine. 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? Does anyone know how I can avoid it from pointing to that directory? Do I need to modify my code or my IIS configuration?

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.


回答1:


No, it's attempting to save the file to 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.

Specify an absolute filename which says exactly where you want the file to be stored, and it should be fine.




回答2:


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


来源:https://stackoverflow.com/questions/16485195/webclient-download-access-to-the-path-c-windows-system32-inetsrv-myprin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!