请求长度超过最大值异常

21

我正在尝试使用上传控件上传一个20兆字节的文件,在Visual Studio内置的Web服务器上运行正常,但一旦发布到生产服务器上(我无法访问),就会不断出现以下错误:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Maximum request length exceeded. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Maximum request length exceeded.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +11140903
   System.Web.HttpRequest.GetMultipartContent() +72
   System.Web.HttpRequest.FillInFormCollection() +245
   System.Web.HttpRequest.get_Form() +119
   System.Web.HttpRequest.get_HasForm() +11072199
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +124
   System.Web.UI.Page.DeterminePostBackMode() +83
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +270



--------------------------------------------------------------------------------

我已将以下内容添加到我的system.web节点中,所以我不知道真正的问题是什么。

<httpRuntime executionTimeout="800" maxRequestLength="51200" />

对此任何指导都将非常有帮助。


您可以在此处查看:https://dev59.com/-m865IYBdhLWcg3wW9RE。它指向相同的解决方案,但是解释了原因。这是微软的方式:https://support.microsoft.com/default.aspx?scid=kb;EN-US;295626。 - Beytan Kurt
3
可能是与“请求长度超出最大限制”相关的重复问题。原链接:https://dev59.com/-m865IYBdhLWcg3wW9RE。 - jball
2个回答

4
如果配置文件更改无效,请尝试直接从IIS更新属性httpRuntime executionTimeout="9200" maxRequestLength="200000">
参考: maxRequestLength

1
尽管您有一个20Mb的文件,但编码或页面上的其他内容可能导致超过您设置的50Mb限制。我建议将当前设置加倍。
还有另一个可能会发挥作用的web.config设置:安全请求过滤maxAllowedContentLength
默认为30MB,但在您的环境中可能设置不同。
web.config条目应类似于:
<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="1550000000" maxQueryString="16384" />
    <fileExtensions>
      <add fileExtension="." allowed="true" />
    </fileExtensions>
  </requestFiltering>
</security>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接