【问题标题】:maxRequestLength+maxAllowedContentLength+HTTPS not workingmaxRequestLength+maxAllowedContentLength+HTTPS 不工作
【发布时间】:2016-04-07 15:35:07
【问题描述】:

我提供了一项托管在 azure webapp 上的服务。这将用于上传文件。 IIS 具有限制文件上传大小的内置安全功能。

为了解决这个问题,我在 web.config 中添加了以下内容

<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="80000000" />
      </requestFiltering>
    </security>
</system.webServer>
...
    <system.web>
       <httpRuntime maxRequestLength="80000" targetFramework="4.5.2" executionTimeout="9000" />
    </system.web>

但这对我不起作用。一旦我上传了一个大文件(例如 50mb),它就会给我一个 404。当我上传一个较小的文件(10mb)时,它工作正常。该服务是一个肥皂,并通过 https 调用。调用没有超时,异常发生在调用的 5 秒内,我猜它上传了 30mb,然后它认为它受到攻击并中止。

我错过了什么吗?

【问题讨论】:

    标签: asp.net azure iis web-applications web-config


    【解决方案1】:

    你可以去文件夹:

    %windir%\system32\inetsrv\

    运行命令:

    appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:80000000
    

    或者如果你只想为你的应用设置它,运行这个:

    appcmd set config "Default Web Site/" -section:requestFiltering -requestLimits.maxAllowedContentLength:80000000
    

    您还需要在 web.config 中将 overrideModeDefault 更新为“允许”:

    <section name="requestFiltering" overrideModeDefault="Allow" />
    

    然后您可以使用 appcmd.exe 更新您的 web.config

    希望this articlethis article 能帮到你。

    关于appcmd.exe的使用方法,可以看https://technet.microsoft.com/en-us/library/cc772200%28v=ws.10%29.aspx

    然后将您的项目部署到 azure webapp 并重试。

    【讨论】:

      【解决方案2】:

      我做了那个配置,但我解决了我在 ControllerBase 上的问题,例如:

              protected override void OnResultExecuting(ResultExecutingContext filterContext)
          {
      
              base.OnResultExecuting(filterContext);
      
              if(filterContext.Result.GetType().Name == "JsonResult")
                  filterContext.Result.GetType().GetProperty("MaxJsonLength").SetValue(filterContext.Result, int.MaxValue);
          }
      

      【讨论】:

        【解决方案3】:

        对于经典 ASP 用户,除了 web.config 设置之外,还要检查此设置:

        IIS > 点击网站 > ASP > 限制属性 > 最大请求实体正文限制

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-02-09
          相关资源
          最近更新 更多