C# HttpException-Chrome中超出了最大请求长度

C# HttpException-Chrome中超出了最大请求长度,c#,asp.net-mvc-3,file-upload,C#,Asp.net Mvc 3,File Upload,我正在使用ASP.NETMVC3中的上载程序。我正在使用AJAX上传控件(http://valums.com/ajax-upload/). 当我试图通过IE上传一个大文件时,一切正常。然而,当我试图通过Chrome上传一个大文件时,我在服务器上遇到一个异常,上面写着“超过了最大长度”。我添加了以下配置设置,认为它可以解决此问题: <httpRuntime maxRequestLength="2147483647" executionTimeout="3600" /> 但这并没有

我正在使用ASP.NETMVC3中的上载程序。我正在使用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");
}
[AcceptVerbs(HttpVerbs.Post)]
公共操作结果上载文件(IEnumerable文件)
{
string home=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,“文件”);
if(String.IsNullOrEmpty(请求[“qqFile”]))
{
字符串文件名=string.Empty;
foreach(Request.Files中的字符串文件)
{
HttpPostedFileBase postedFile=(HttpPostedFileBase)(Request.Files[file]);
if(postedFile.ContentLength==0)
继续;
filename=Path.Combine(home,Path.GetFileName(postedFile.filename));
if(Directory.Exists(baseDirectory)=false)
CreateDirectory(baseDirectory);
postedFile.SaveAs(文件名);
}
}
其他的
{
//我的问题就在这里
字符串文件名=Path.Combine(baseDirectory,Request[“qqFile”]);
byte[]buffer=新字节[Request.InputStream.Length];
Request.InputStream.Read(buffer,0,buffer.Length);
System.IO.File.writealBytes(文件名、缓冲区);
}
返回Json(新的{success=true},“text/html”);
}

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

您可以尝试设置maxAllowedContentLength

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