【问题标题】:Large file doesn't upload in ASP.NET大文件不会在 ASP.NET 中上传
【发布时间】:2015-01-20 05:09:38
【问题描述】:

我有一个 asp.net 网络表单应用程序,我正在尝试使用 FileUpload 控件在网络表单中上传一个大文件 (13 mb),当我按下提交按钮时,网络浏览器开始上传文件。但是,当网络浏览器完成上传时,应用程序无故崩溃,并且没有引发任何异常,并且没有进入提交按钮的点击事件代码(c#)。在我的 web.config 中,我设置了 maxAllowedContentLength 选项和 maxRequestLength 选项。

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

<httpRuntime targetFramework="4.5" executionTimeout="900" maxRequestLength="2097151" />

这仅发生在 Web 服务器(Windows Server 2012)中,在我的本地服务器中没有发生。在网络服务器中显示默认错误(我不管理服务器,所以我看不到发生了什么自定义错误)

我不知道为什么会这样,因为在 Web 服务器中的应用程序的文件上传选项更大。

感谢您的帮助。

【问题讨论】:

  • 我的第一个权限是对您要上传到的文件夹的权限。这是您之前上传的文件夹吗?你能管理文件夹的权限吗?
  • 我可以上传该文件夹中最小的文件。在“所有人”文件夹中可以读写文件。上传文件后,writefile代码不执行。

标签: c# asp.net file upload


【解决方案1】:

您的 web.config 中似乎缺少打开的“安全”标签

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

【讨论】:

  • 对不起,我是手动写的,忘记放了。在我原来的 web.config 中,开始标签就在那里。
【解决方案2】:

如果您的 maxAllowedContentLength 值很大,那么您的 executionTimeout 也必须很大! 它可以在本地工作,因为您不需要很长时间即可将文件复制到硬盘中。 但是当您在服务器中上传您的网站时,您需要更多的 executionTimeout。

【讨论】:

  • 将 executionTimeout 标签添加到您的 web.config 中,并具有较大的值。
  • 改成90000这样的大数。
  • 您的 maxRequestLength 非常大,它需要并且需要非常大的 executionTimeout。
  • 在你的 web.config 文件中添加一个大值的 executionTimeout。
【解决方案3】:

按照 Stricture 修改您的 web.config,这里我使用最大文件请求长度 13 MB 和最大允许内容长度 1 GB。
现在改web.config中&lt;system.web&gt;后面

<httpRuntime targetFramework="4.5" maxRequestLength="13631488" executionTimeout="9000" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="1000" />

并在 web config 中的 &lt;system.webServer&gt; 后面写下这段代码

<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="1073741824" />
  </requestFiltering>
</security>

谢谢

【讨论】:

    【解决方案4】:

    问题是管理员对服务器的限制不允许上传大文件。该线程中给出的所有配置都是正确的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-06
      • 2016-03-23
      • 1970-01-01
      • 2012-12-08
      • 2010-12-08
      • 1970-01-01
      • 2011-04-30
      • 2010-10-16
      相关资源
      最近更新 更多