【问题标题】:MVC Maximum request length exceeded超出 MVC 最大请求长度
【发布时间】:2014-10-07 14:57:18
【问题描述】:

我有一个 MVC 解决方案。解决方案中有一个动作:

public FileResult ExportPdf(string pdfHtml, string pdfIdentifier)
{  
}

当我提交表单时,我的 javascript 会使用文本数据(当前页面的 base64 格式的 html)初始化一个隐藏字段 pdfHtml。所以这个字段可能大于 10mb。

function ExportPDF() {

    document.getElementById('pdfHtml').value = window.btoa(unescape(encodeURIComponent(document.getElementById('Report').outerHTML)));
    document.getElementById('exportForm').submit();
}

当我发帖时,我有一个错误

异常:System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException:出现异常 运行配置文件中指定的扩展。 ---> System.Web.HttpException:超出最大请求长度。在 System.Web.HttpRequest.GetEntireRawContent()

我知道 web.config 文件中的配置。所以我这样做了:

<system.web>
<httpRuntime requestValidationMode="2.0" maxRequestLength="1147483647"  executionTimeout="200" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="3294967295" />
      </requestFiltering>
 </security>
</system.webServer>

但我仍然收到此错误。我对这个问题失去了理智,不知道问题是什么。

【问题讨论】:

  • 设置HttpContext.Server.ScriptTimeout 属性怎么样?
  • @Murali 我设置了 executionTimeout="200",是一样的
  • @Murali 更准确地说,我在我的 DNA 中发现了错误。此错误是由在 ExportPdf 函数中调用的远程服务生成的,而不是在我的代码中。

标签: asp.net-mvc


【解决方案1】:
<httpRuntime maxRequestLength="1048576" requestValidationMode="2.0" enableVersionHeader="false" targetFramework="4.5" />

将此添加到您的网络配置中。错误将得到解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-20
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    相关资源
    最近更新 更多