我正在使用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上传大文件?
答案 0 :(得分:2)
您可以尝试设置maxAllowedContentLength
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="X" />
</requestFiltering>
</security>
</system.webServer>