简体   繁体   English

文件上传在 Visual Studio IIS Express 中工作但不在服务器上

[英]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:这是检查清单:

  1. Do you use Windows authentication on the failing server?您是否在出现故障的服务器上使用 Windows 身份验证?
  2. Are you running Application pull under service account or ApplicationPoolIdentity?您是在服务帐户或 ApplicationPoolIdentity 下运行 Application pull 吗?
  3. Does your target folder security allows Read/Right access to that account?您的目标文件夹安全性是否允许对该帐户的读取/权限访问?

如果代码在 IIS Express 但不是 IIS 中运行时保存文件,那么它的主要问题是 App Pool Identity 没有访问您尝试保存文件的目录的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 文件上载在IIS Express中有效,但在本地IIS上无效 - The file upload working in IIS express but not working on local IIS Visual Studio 2019“无法连接到 web 服务器‘IIS Express’” - Visual studio 2019 “Unable to connect to web server 'IIS Express'” Visual Studio的IIS Express:无法加载文件或程序集 - Visual Studio's IIS Express: Could not load file or assembly Visual Studio / IIS Express间歇性错误 - Visual Studio/IIS Express Intermittent Bugs Visual Studio 找不到 IIS Express - Visual Studio can't find IIS Express 使用IIS Express / Visual Studio进行SimpleInjector验证过程 - SimpleInjector Verification process with IIS Express / Visual Studio 在 Visual Studio 中运行 IIS-Express 时出错 - Error running IIS-Express in Visual Studio 是否可以针对iis Express在Visual Studio中的app_code中调试类文件或剃刀文件? - Is it possible to debug class file or razor file in app_code inside visual studio against iis express? System.NullReferenceException for .NET 服务在 Windows Server IIS 上运行,但在 Visual Studio IIS Express 中运行时在本地工作 - System.NullReferenceException for .NET service running on windows server IIS but works locally when running in Visual Studio IIS Express 使用api无法在IIS上载文件 - Upload file with api not working on IIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM