diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs index c2b06f2705..5729c9b0cb 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs @@ -76,6 +76,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration return; } + var bodySizeFeature = httpContext.Features.Get(); + if (bodySizeFeature != null) + { + // IIS already limits this, no need to do it twice. + bodySizeFeature.MaxRequestBodySize = null; + } + if (_options.ForwardClientCertificate) { var header = httpContext.Request.Headers[MSAspNetCoreClientCert]; diff --git a/test/IISIntegration.FunctionalTests/HelloWorldTest.cs b/test/IISIntegration.FunctionalTests/HelloWorldTest.cs index 0dd43ef904..011fa521b4 100644 --- a/test/IISIntegration.FunctionalTests/HelloWorldTest.cs +++ b/test/IISIntegration.FunctionalTests/HelloWorldTest.cs @@ -81,6 +81,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests response = await deploymentResult.HttpClient.GetAsync("/Query%3FPath?query?"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("?query?", responseText); + + response = await deploymentResult.HttpClient.GetAsync("/BodyLimit"); + responseText = await response.Content.ReadAsStringAsync(); + Assert.Equal("null", responseText); } catch (XunitException) { diff --git a/test/TestSites/StartupHelloWorld.cs b/test/TestSites/StartupHelloWorld.cs index 3d782199cd..41696fb9fb 100644 --- a/test/TestSites/StartupHelloWorld.cs +++ b/test/TestSites/StartupHelloWorld.cs @@ -1,8 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; namespace TestSites @@ -21,9 +22,14 @@ namespace TestSites { return ctx.Response.WriteAsync(ctx.Request.QueryString.Value); } + if (ctx.Request.Path.Value.StartsWith("/BodyLimit")) + { + return ctx.Response.WriteAsync( + ctx.Features.Get()?.MaxRequestBodySize?.ToString() ?? "null"); + } return ctx.Response.WriteAsync("Hello World"); }); } } -} \ No newline at end of file +}