【问题标题】:How to upload large files in ASP.Net MVC 4如何在 ASP.Net MVC 4 中上传大文件
【发布时间】:2014-08-22 22:45:48
【问题描述】:

如何在 ASP.Net MVC 4 中上传大文件

我在控制器中有这样的代码:

Request.Files.Get("img").SaveAs(Server.MapPath("~/Images/ImgSong/" + +Out.Id + ".jpg"));

它只允许上传一个小文件,而我要上传的文件将 范围从 10Mb 到 100Mb。

请帮帮我。

【问题讨论】:

    标签: asp.net-mvc-4 upload large-file-upload


    【解决方案1】:

    你需要改变你的 web.config:

    <configuration>
      <system.web>
        <httpRuntime maxRequestLength="4096" />
      </system.web>
    </configuration>
    

    默认值为 4096kb。您需要将此值更改为 10240 才能上传 10mb。

    【讨论】:

    • 我必须按照你的指示做,但仍然有错误,这是图片![在此处输入图片描述][1]i.stack.imgur.com/y6xVK.png
    • 此错误意味着您在 web.config 上有 标签,但没有 configsections。如果不运行,您能否仅尝试使用我的代码而不是仅尝试 @Kamlesh 的代码。顺便说一下,您已经有了 部分。你只需要写 httpruntime 的东西。
    【解决方案2】:

    根据文件大小编辑您的web.config

    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" maxRequestLength="10240" executionTimeout="1600" requestLengthDiskThreshold="10240" />
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="10240" />
          </requestFiltering>
        </security>
        ...
    </system.web>
    

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 2014-08-06
      • 2013-04-23
      • 2010-10-16
      • 1970-01-01
      • 2011-03-13
      • 2012-07-27
      • 1970-01-01
      • 2010-11-05
      相关资源
      最近更新 更多