简体   繁体   English

ASP.NET 核心 web.config requestFiltering 不覆盖 applicationhost.config

[英]ASP.NET Core web.config requestFiltering not overriding applicationhost.config

I'm trying to upload large files to an API controller action in my ASP.NET Core MVC 2.1 application.我正在尝试在我的 ASP.NET Core MVC 2.1 应用程序中将大文件上传到 API controller 操作。 To that end I've been trying to figure out how to allow this through IIS Express which is how I'm running the application through Visual Studio.为此,我一直试图弄清楚如何通过 IIS Express 来实现这一点,这就是我通过 Visual Studio 运行应用程序的方式。 As suggested, this should be possible by adding a web.config file to the project root with the following contents:正如所建议的,这应该可以通过将web.config文件添加到项目根目录中,其中包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<!-- Configuration for IIS integration -->
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 2 GB -->
        <requestLimits maxAllowedContentLength="2147483647" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

However, this doesn't have any effect as the application just returns HTTP Error 404.13 - Not Found , indicating the request is too large.但是,这没有任何效果,因为应用程序只是返回HTTP Error 404.13 - Not Found ,表明请求太大。 It seems as if those settings are locked by the IIS so the web.config isn't overriding them.这些设置似乎被 IIS 锁定,因此web.config没有覆盖它们。 Yes, I'm also using attributes such as [DisableFormValueModelBinding] and [DisableRequestSizeLimit] on the controller action.是的,我还在 controller 操作中使用[DisableFormValueModelBinding][DisableRequestSizeLimit]等属性。

Instead I found that it works by adding the same configuration to the site in the applicationhost.config in the \.vs\config folder:相反,我发现它可以通过在\.vs\config文件夹中的applicationhost.config中的站点中添加相同的配置来工作:

  <location path="MySite">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" requestTimeout="23:00:00" />
      <httpCompression>
        <dynamicTypes>
          <add mimeType="text/event-stream" enabled="false" />
        </dynamicTypes>
      </httpCompression>
      <!-- Everything above this point is auto-generated -->
      <security>
        <requestFiltering>
          <!-- 2 GB -->
          <requestLimits maxAllowedContentLength="2147483647" />
        </requestFiltering>
      </security>
    </system.webServer>
  </location>

This file, however, is not tracked in GIT and it doesn't seem like a good solution to add it to GIT either.然而,这个文件在 GIT 中没有被跟踪,而且将它添加到 GIT 似乎也不是一个好的解决方案。

Is there some security reason or other for why the web.config seemingly is not allowed to override the applicationhost.config ?为什么web.config似乎不允许覆盖applicationhost.config是否有一些安全原因或其他原因? Or is there a solution that I just haven't been able to figure out?还是有我无法弄清楚的解决方案?

I had a similar issue, I added a web.config with this我有一个类似的问题,我用这个添加了一个 web.config

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- This will handle requests up to 700MB (CD700) -->
        <requestLimits maxAllowedContentLength="737280000" />
      </requestFiltering>
    </security>
  </system.webServer>][1]][1]
</configuration>

posted too soon.发布得太早了。 The above solution worked for iis express server but did not for docker.上述解决方案适用于 iis 快递服务器,但不适用于 docker。 Then I updated the entry然后我更新了条目

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseKestrel(options =>
        {
            options.Limits.MaxRequestBodySize = 100000000; //100MB
        });

Then decorate controllers with [RequestSizeLimit(100_000_000)]然后用[RequestSizeLimit(100_000_000)]装饰控制器

Those solutions solved locally and in prod for me.这些解决方案在本地解决并为我生产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM