【发布时间】:2016-08-25 16:14:05
【问题描述】:
当我尝试上传图像并将其保存在服务器的某个文件夹中时,file.SaveAs(path) 行中出现错误System.UnauthorizedAccessException。
查看:
控制器:
public ActionResult LoadImage()
{
return View();
}
public ActionResult Upload(HttpPostedFileBase file)
{
//String path = Server.MapPath("~/img/" + file.FileName);
if (file != null)
{
String pic = System.IO.Path.GetFileName(file.FileName);
String path = System.IO.Path.Combine(Server.MapPath("~"), pic);
file.SaveAs(path);
}
return RedirectToAction("index", "Home", null);
【问题讨论】:
标签: image file-upload directory asp.net-mvc-5