.NET MVC3无法通过文件上传上传大文件 [英] .NET MVC3 Can't upload large files via FileUpload

查看:333
本文介绍了.NET MVC3无法通过文件上传上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来在我的.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>
 

解决方案

的<一个href="http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits">maxAllowedContentLength属性是在字节:

 &LT; requestLimits maxAllowedContentLength =10485760/&GT;
 

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

做你 的maxRequestLength 这是KB:

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

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

 &LT; system.webServer&GT;
    &LT;安全&GT;
        &LT;的requestFiltering&GT;
            &LT;! - 限制文件上传到55MB  - &GT;
            &LT; requestLimits maxAllowedContentLength =57671680/&GT;
        &LT; /的requestFiltering&GT;
    &LT; /安全&GT;
&LT; /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>

这篇关于.NET MVC3无法通过文件上传上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆