XMLHttpRequest发送文件请求对于大文件给出404错误

XMLHttpRequest send file request gives 404 error for big files

本文关键字:文件 错误 于大 请求 XMLHttpRequest      更新时间:2023-09-26

我在mvc 4项目中有一个控制器操作,它获取包括文件的POST请求。我正在用XMLHttpRequest向服务器发布数据。当我选择10mb或更小的文件上传时,上传过程是成功的。但当我选择上传40Mb文件时,会出现404错误。

Failed to load resource: the server responded with a status of 404 (Not Found) 

var formData = new window.FormData();
formData.append(this.file.name, this.file);
this.ajax = new XMLHttpRequest();
this.ajax.open("POST", "@Url.Action("FileUpload", "MyController", new { id = Model.Id })");
this.ajax.send(formData);

我在我的操作方法中设置了一个断点,小文件被捕获,但大文件请求没有到达服务器,直接在浏览器控制台上给出404错误。

我的操作方法是这样的:

 [HttpPost]
 public ActionResult FileUpload(string id)
 {
     return Json("", JsonRequestBehavior.AllowGet);
 }

我设置了这样的网络配置文件限制。

<httpRuntime targetFramework="4.5"
             maxRequestLength="2000000000" 
             executionTimeout="300"/>

您可以这样设置web配置的安全设置。

<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="2000000000"/>    
  </requestFiltering>
</security>