问题
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