【问题标题】:HttpException - Maximum request length exceeded in ChromeHttpException - Chrome 中超出了最大请求长度
【发布时间】:2012-01-13 19:36:28
【问题描述】:

我正在使用 ASP.NET MVC 3 中的上传器。我正在使用 AJAX 上传控件 (http://valums.com/ajax-upload/)。当我尝试通过 IE 上传大文件时,一切正常。但是,当我尝试通过 Chrome 上传大文件时,我在服务器上收到“超出最大长度”的异常。我添加了以下配置设置,认为它会解决它:

<httpRuntime maxRequestLength="2147483647" executionTimeout="3600" />

但这并没有解决它。我的操作代码如下所示:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
  string home = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "files");
  if (String.IsNullOrEmpty(Request["qqFile"]))
  {
    string filename = string.Empty;
    foreach (string file in Request.Files)
    {
      HttpPostedFileBase postedFile = (HttpPostedFileBase)(Request.Files[file]);
      if (postedFile.ContentLength == 0)
        continue;

      filename = Path.Combine(home, Path.GetFileName(postedFile.FileName));
      if (Directory.Exists(baseDirectory) == false)
        Directory.CreateDirectory(baseDirectory);
      postedFile.SaveAs(filename);
    }
  }
  else
  {
    // MY PROBLEM IS IN HERE
    string filename = Path.Combine(baseDirectory, Request["qqFile"]);

    byte[] buffer = new byte[Request.InputStream.Length];
    Request.InputStream.Read(buffer, 0, buffer.Length);
    System.IO.File.WriteAllBytes(filename, buffer);
  }

  return Json(new { success = true }, "text/html");
}

为什么我不能通过 Chrome 上传更大的文件?

【问题讨论】:

    标签: c# asp.net-mvc-3 file-upload


    【解决方案1】:

    您可以尝试设置 maxAllowedContentLength

    <system.webServer>
        <security>
            <requestFiltering>
                 <requestLimits maxAllowedContentLength="X" />
            </requestFiltering>
        </security>
    </system.webServer>
    

    【讨论】:

      猜你喜欢
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      • 2011-04-20
      • 2012-10-08
      • 2015-11-02
      • 1970-01-01
      相关资源
      最近更新 更多