How to upload large files in ASP.Net MVC 4

强颜欢笑 提交于 2019-12-24 13:25:54

问题


How to upload large files in ASP.Net MVC 4

I have code like this in the controller:

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

It only allows uploading a small file, while the file I want to upload would range from 10Mb to 100Mb.

Please help me.


回答1:


You need to change you web.config:

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

The default value is 4096kb. You need to change this value to 10240 for 10mb uploading.




回答2:


Edit your web.config as per size of file.

<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>


来源:https://stackoverflow.com/questions/24526106/how-to-upload-large-files-in-asp-net-mvc-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!