[英]File upload working in Visual Studio IIS Express but not on server
I have a view on a web application where a file is uploaded by a user to pre-fill a form.我在 Web 应用程序上有一个视图,其中用户上传了一个文件来预填表单。 The view on which the form is located has two
Html.BeginForm
declarations, one to upload the file, and one to submit the filled form.表单所在的视图有两个
Html.BeginForm
声明,一个用于上传文件,另一个用于提交填写好的表单。 Everything works fine when I debug locally using IIS Express, but when I deploy to my development server, the file does not upload.当我使用 IIS Express 在本地调试时一切正常,但是当我部署到我的开发服务器时,文件没有上传。 I am hoping someone might be able to provide some insight into why this is occurring.
我希望有人能够提供一些有关为什么会发生这种情况的见解。
File upload excerpt from view:文件上传摘自视图:
@using (Html.BeginForm("Populate", "ScProject", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
//file upload and submit button
}
File upload excerpt from controller:来自控制器的文件上传摘录:
[HttpPost]
public ActionResult Populate(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
try
{
string path = Path.Combine(Server.MapPath("~/Content"), System.IO.Path.GetFileName(file.FileName));
file.SaveAs(path);
return RedirectToAction("Create", new { file = Path.GetFileName(file.FileName) });
}
catch (Exception ex)
{
...omitted error logging code...
return RedirectToAction("Create");
}
else
{
...omitted error logging code...
return RedirectToAction("Create");
}
}
The RedirectToAction("Create", new { file = Path.GetFileName(file.FileName) });
RedirectToAction("Create", new { file = Path.GetFileName(file.FileName) });
reloads the view and populates the form using the uploaded file.重新加载视图并使用上传的文件填充表单。 I have attempted to execute this action using a pre-uploaded file by entering a url:
../ScProject/Create?file=upload.pptx
which again, works fine on IIS Express, but fails on the development server.我试图通过输入一个 url 使用预先上传的文件执行此操作:
../ScProject/Create?file=upload.pptx
file= ../ScProject/Create?file=upload.pptx
再次在 IIS Express 上工作正常,但在开发服务器上失败。 If anyone can offer any insight it would be greatly appreciated.如果有人可以提供任何见解,将不胜感激。
Here is the check list:这是检查清单:
如果代码在 IIS Express 但不是 IIS 中运行时保存文件,那么它的主要问题是 App Pool Identity 没有访问您尝试保存文件的目录的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.