Skip to content

Commit dc8d338

Browse files
authored
Merge pull request #11052 from umbraco/v9/bugfix/AB13489-no-error-when-exceeding-maxAllowedContentLength
V9: Update MaxRequestBodySize on both IIS Server and Kestrel Server
2 parents 898f270 + 3ffbbf6 commit dc8d338

File tree

6 files changed

+438
-380
lines changed

6 files changed

+438
-380
lines changed

src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public static IUmbracoBuilder AddUmbraco(
103103
var requestCache = new HttpContextRequestAppCache(httpContextAccessor);
104104
var appCaches = AppCaches.Create(requestCache);
105105

106+
services.ConfigureOptions<ConfigureKestrelServerOptions>();
107+
services.ConfigureOptions<ConfigureIISServerOptions>();
108+
services.ConfigureOptions<ConfigureFormOptions>();
109+
106110
IProfiler profiler = GetWebProfiler(config);
107111

108112
ILoggerFactory loggerFactory = LoggerFactory.Create(cfg => cfg.AddSerilog(Log.Logger, false));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Http.Features;
2+
using Microsoft.Extensions.Options;
3+
using Umbraco.Cms.Core.Configuration.Models;
4+
5+
namespace Umbraco.Cms.Web.Common.Security
6+
{
7+
public class ConfigureFormOptions : IConfigureOptions<FormOptions>
8+
{
9+
private readonly IOptions<RuntimeSettings> _runtimeSettings;
10+
11+
public ConfigureFormOptions(IOptions<RuntimeSettings> runtimeSettings) => _runtimeSettings = runtimeSettings;
12+
public void Configure(FormOptions options)
13+
{
14+
// convert from KB to bytes
15+
options.MultipartBodyLengthLimit = _runtimeSettings.Value.MaxRequestLength.HasValue ? _runtimeSettings.Value.MaxRequestLength.Value * 1024 : long.MaxValue;
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.Options;
3+
using Umbraco.Cms.Core.Configuration.Models;
4+
5+
namespace Umbraco.Cms.Web.Common.Security
6+
{
7+
public class ConfigureIISServerOptions : IConfigureOptions<IISServerOptions>
8+
{
9+
private readonly IOptions<RuntimeSettings> _runtimeSettings;
10+
11+
public ConfigureIISServerOptions(IOptions<RuntimeSettings> runtimeSettings) => _runtimeSettings = runtimeSettings;
12+
public void Configure(IISServerOptions options)
13+
{
14+
// convert from KB to bytes
15+
options.MaxRequestBodySize = _runtimeSettings.Value.MaxRequestLength.HasValue ? _runtimeSettings.Value.MaxRequestLength.Value * 1024 : uint.MaxValue; // ~4GB is the max supported value for IIS and IIS express.
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Server.Kestrel.Core;
2+
using Microsoft.Extensions.Options;
3+
using Umbraco.Cms.Core.Configuration.Models;
4+
5+
namespace Umbraco.Cms.Web.Common.Security
6+
{
7+
public class ConfigureKestrelServerOptions : IConfigureOptions<KestrelServerOptions>
8+
{
9+
private readonly IOptions<RuntimeSettings> _runtimeSettings;
10+
11+
public ConfigureKestrelServerOptions(IOptions<RuntimeSettings> runtimeSettings) => _runtimeSettings = runtimeSettings;
12+
public void Configure(KestrelServerOptions options)
13+
{
14+
// convert from KB to bytes
15+
options.Limits.MaxRequestBodySize = _runtimeSettings.Value.MaxRequestLength.HasValue ? _runtimeSettings.Value.MaxRequestLength.Value * 1024 : long.MaxValue;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)