我在这里做错了什么,但无法弄清楚。我有一个虚拟目录和一个文件在里面,我想下载文件。从虚拟目录下载文件
我的代码:
public ActionResult DownloadFile()
{
string FileName = Request.Params["IMS_FILE_NAME"];
string FullFileLogicalPath = Path.Combine(ConfigurationManager.AppSettings["VIRTUAL_DIR_PATH"], FileName);
string FullfilePhysicalPath = Path.Combine(ConfigurationManager.AppSettings["PHYSICAL_DIR_PATH"], FileName);
if (System.IO.File.Exists(FullfilePhysicalPath))
{
return File(FullFileLogicalPath , "Application/pdf", DateTime.Now.ToLongTimeString());
}
else
{
return Json(new { Success = "false" });
}
}
我得到一个错误:
http:/localhost/Images/PDF/150763-3.pdf is not a valid virtual path.
如果我在我的浏览器发布此URL http:/localhost/Images/PDF/150763-3.pdf
,文件被打开。我怎样才能下载这个文件?
平台MVC 4,IIS 8
在你的代码的行,你得到这个错误? –
在Application.Error() –
方法中的Global.asax中出现错误使用IIS 7.5可以正常工作。 – misak