Skip to content

Commit fbdf290

Browse files
committed
cleanup
1 parent 2de9646 commit fbdf290

File tree

8 files changed

+55
-8
lines changed

8 files changed

+55
-8
lines changed

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ IN_PROCESS_APPLICATION::ExecuteApplication()
252252
}
253253

254254
// Used to make .NET Runtime always log to event log when there is an unhandled exception.
255-
LOG_LAST_ERROR_IF(SetEnvironmentVariable(L"COMPlus_UseEntryPointFilter", L"1"));
255+
LOG_LAST_ERROR_IF(!SetEnvironmentVariable(L"COMPlus_UseEntryPointFilter", L"1"));
256256

257257
bool clrThreadExited;
258258
{

src/Servers/IIS/IIS/src/Core/IISHttpContext.FeatureCollection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.AspNetCore.Http.Features.Authentication;
1717
using Microsoft.AspNetCore.Server.IIS.Core.IO;
1818
using Microsoft.AspNetCore.WebUtilities;
19+
using Microsoft.Extensions.Logging;
1920

2021
namespace Microsoft.AspNetCore.Server.IIS.Core
2122
{
@@ -342,10 +343,12 @@ unsafe X509Certificate2 ITlsConnectionFeature.ClientCertificate
342343
{
343344
throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired);
344345
}
346+
345347
if (value > _options.IisMaxRequestSizeLimit)
346348
{
347-
_logger.LogWarning("Cannot increase request size past IIS limit.");
349+
_logger.LogWarning(CoreStrings.MaxRequestLimitWarning);
348350
}
351+
349352
MaxRequestBodySize = value;
350353
}
351354
}

src/Servers/IIS/IIS/src/Core/IISHttpServer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ ILogger<IISHttpServer> logger
8181
}
8282

8383
Features.Set<IServerAddressesFeature>(_serverAddressesFeature);
84+
85+
if (_options.MaxRequestBodySize > _options.IisMaxRequestSizeLimit)
86+
{
87+
_logger.LogWarning(CoreStrings.MaxRequestLimitWarning);
88+
}
8489
}
8590

8691
public Task StartAsync<TContext>(IHttpApplication<TContext> application, CancellationToken cancellationToken)

src/Servers/IIS/IIS/src/CoreStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,7 @@
162162
<data name="BadRequest" xml:space="preserve">
163163
<value>Bad request.</value>
164164
</data>
165+
<data name="MaxRequestLimitWarning" xml:space="preserve">
166+
<value>Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength. HTTP requests that have a content length greater than maxAllowedContentLength will still be rejected by IIS. You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit.</value>
167+
</data>
165168
</root>

src/Servers/IIS/IIS/src/Properties/CoreStrings.Designer.cs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
4646
options => {
4747
options.ServerAddresses = iisConfigData.pwzBindings.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
4848
options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled;
49-
if (options.MaxRequestBodySize > iisConfigData.maxRequestBodySize)
50-
{
51-
// Log warning and set the max to the IIS limit
52-
options.MaxRequestBodySize = iisConfigData.maxRequestBodySize;
53-
}
5449
options.IisMaxRequestSizeLimit = iisConfigData.maxRequestBodySize;
5550
}
5651
);

src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/MaxRequestBodySizeTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
using System.Net;
55
using System.Net.Http;
66
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Server.IIS;
78
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
9+
using Microsoft.AspNetCore.Server.IntegrationTesting;
810
using Microsoft.AspNetCore.Server.IntegrationTesting.IIS;
911
using Microsoft.AspNetCore.Testing.xunit;
1012
using Xunit;
@@ -47,8 +49,33 @@ public async Task SetIISLimitMaxRequestBodySizeE2EWorks()
4749
var deploymentResult = await DeployAsync(deploymentParameters);
4850

4951
var result = await deploymentResult.HttpClient.PostAsync("/ReadRequestBody", new StringContent("test"));
52+
5053
// IIS returns a 404 instead of a 413...
5154
Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
5255
}
56+
57+
[ConditionalFact]
58+
[RequiresNewHandler]
59+
[RequiresIIS(IISCapability.PoolEnvironmentVariables)]
60+
public async Task SetIISLimitMaxRequestBodyLogsWarning()
61+
{
62+
var deploymentParameters = Fixture.GetBaseDeploymentParameters();
63+
deploymentParameters.ServerConfigActionList.Add(
64+
(config, _) => {
65+
config
66+
.RequiredElement("system.webServer")
67+
.GetOrAdd("security")
68+
.GetOrAdd("requestFiltering")
69+
.GetOrAdd("requestLimits", "maxAllowedContentLength", "1");
70+
});
71+
var deploymentResult = await DeployAsync(deploymentParameters);
72+
73+
var result = await deploymentResult.HttpClient.PostAsync("/DecreaseRequestLimit", new StringContent("1"));
74+
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
75+
76+
Assert.Single(TestSink.Writes, w => w.Message == "Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength." +
77+
" HTTP requests that have a content length greater than maxAllowedContentLength will still be rejected by IIS." +
78+
" You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit.");
79+
}
5380
}
5481
}

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static int Main(string[] args)
112112
.UseIIS()
113113
.ConfigureServices(services =>
114114
{
115-
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 1);
115+
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 2);
116116
})
117117
.UseStartup<Startup>()
118118
.Build();

0 commit comments

Comments
 (0)