【问题标题】:File size exceeds default size during uploading上传时文件大小超出默认大小
【发布时间】:2013-05-06 16:17:18
【问题描述】:

我在 ASP.NET MVC 中工作。我正在尝试上传文件,在小文件的情况下成功,但如果文件很大,我会收到以下错误。

Maximum request length exceeded.

以下是我的表格。

@using (@Html.BeginForm("Method","Controller",FormMethod.Post,new{enctype="multipart/form-data"}))
{
   <input type="file" name="file" id="file"/>
   <input type="submit" value="Submit"/>
}

以下是控制器方法。

[HttpPost]
public ActionResult Method(HttpFileBase file)
{
    string path = System.IO.Path.Combine(Server.MapPath("~/Files"), file.FileName);

    file.SaveAs(path);
}

当文件较小(即 1-2Mb)时,相同的代码可以正常工作,但我正在尝试上传未上传的 19Mb 文件。我不知道如何指定文件长度以及如何删除上述错误。请帮帮我。

【问题讨论】:

标签: asp.net asp.net-mvc asp.net-mvc-3 razor


【解决方案1】:

在 System.Web 节点下的 web.config 中指定

<httpRuntime maxRequestLength="NNN" />

NNN 是以千字节为单位的文件大小

【讨论】:

  • 从浏览器请求以下代码时发现错误。''
  • @FakharuzZaman:你做错了。那里应该只有一个 httpRuntime 节点。像
【解决方案2】:

在system.web 下的web.config 文件中添加这些设置:

<system.web>
  ....
   <httpRuntime maxRequestLength="XXXX" executionTimeout="XXXX" />
  ....
</system.web>

maxRequestLength 在 kb 中,executionTimeout 在 分钟 中。你应该设置executionTimeout给它足够的时间来上传文件。

查看this了解更多详情。

【讨论】:

    【解决方案3】:

    您可以按照此处的建议使用 web.config 更改最大上传大小,但我建议将该更改绑定到您希望将其上传到的确切 URL。例如,这会将最大上传大小更改为 50MB。

    <location path="Documents/Upload">
      <system.web>
        <httpRuntime maxRequestLength="51200" />
      </system.web>
    </location>
    

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 1970-01-01
      • 2011-07-06
      • 2015-01-20
      • 2020-04-24
      • 2020-10-15
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多