.NET MVC3无法通过文件上传上传大文件文件上传、大文件、上传、NET

2023-09-11 09:19:50 作者:柠溪

我需要一种方法来在我的.NET MVC3网站(托管在亚马逊)上传大文件(50 + MB)。在尝试上载一个大的zip文件(36.9MB)FireFox中显示连接被重置屏幕,萤火显示中止状态下。

这是我怎么能解决这个问题的任何想法?

控制器:

 私人无效SAVEFILE(HttpPostedFileBase UploadedFile的)
{
    使用(var文件= System.IO.File.Create(使用Server.Mappath(/上传/+ uploadedFile.FileName))
        uploadedFile.InputStream.CopyTo(文件);
}
 

Web.config文件:

 <的System.Web>
    <的httpRuntime maxRequestLength的=56320executionTimeout =1500/>
< /system.web>

  < system.webServer>
    <安全>
      <的requestFiltering>
        < requestLimits maxAllowedContentLength =10485760/>
      < /的requestFiltering>
    < /安全>
  < /system.webServer>
 
ProASP.NETMVC3Framework Web开发文档类资源 CSDN下载

解决方案

的maxAllowedContentLength属性是在字节:

 < requestLimits maxAllowedContentLength =10485760/>
 

10485760字节= 10MB。所以,如果您尝试上传的文件是超过10MB你会失败更大。

做你 的maxRequestLength 这是KB:

 <的System.Web>
    <! - 限制文件上传到55MB  - >
    <的httpRuntime maxRequestLength的=56320executionTimeout =1500/>
< /system.web>
 

这表明55MB和你的 requestLimits 的限制。像这样的:

 < system.webServer>
    <安全>
        <的requestFiltering>
            <! - 限制文件上传到55MB  - >
            < requestLimits maxAllowedContentLength =57671680/>
        < /的requestFiltering>
    < /安全>
< /system.webServer>
 

I need a way to upload large files (50+ MB) in my .net mvc3 website (hosted on Amazon). After trying to upload a large zip file (36.9MB) FireFox shows "The connection was reset" screen and FireBug shows "Aborted" under status.

Any ideas on how I could solve it?

Controller:

private void SaveFile(HttpPostedFileBase uploadedFile)
{
    using (var file = System.IO.File.Create(Server.MapPath("/uploads/" + uploadedFile.FileName))
        uploadedFile.InputStream.CopyTo(file);
}

Web.config:

  <system.web>
    <httpRuntime maxRequestLength="56320" executionTimeout="1500"/>
</system.web>

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength= "10485760"/>
      </requestFiltering>
    </security>
  </system.webServer>

解决方案

The maxAllowedContentLength property is in bytes:

<requestLimits maxAllowedContentLength= "10485760"/>

10485760 bytes = 10MB. So if you try to upload a file that is larger than 10MB you will fail.

Be consistent between your maxRequestLength which is in KB:

<system.web>
    <!-- Limit file uploads to 55MB -->
    <httpRuntime maxRequestLength="56320" executionTimeout="1500"/>
</system.web>

which indicates a limit of 55MB and your requestLimits. Like this:

<system.webServer>
    <security>
        <requestFiltering>
            <!-- Limit file uploads to 55MB -->
            <requestLimits maxAllowedContentLength="57671680"/>
        </requestFiltering>
    </security>
</system.webServer>