【问题标题】:XMLHttpRequest send file request gives 404 error for big filesXMLHttpRequest 发送文件请求为大文件提供 404 错误
【发布时间】:2014-06-16 19:59:12
【问题描述】:

我的 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);

我在action方法下放了一个断点,小文件post被抓到但是大文件请求没有到达服务器,直接在浏览器控制台报404错误。

我的动作方法是这样的:

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

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

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

【问题讨论】:

    标签: javascript asp.net ajax asp.net-mvc


    【解决方案1】:

    您可以像这样设置您的网络配置安全设置。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      • 2021-04-23
      • 1970-01-01
      • 2013-09-14
      • 2020-12-31
      • 1970-01-01
      相关资源
      最近更新 更多