Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Add new settings in AppSettings - Allow to set MaxRequestBodySize

support4522aeb92e41
diff --git a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
index 6146c3352..1ed27d99e 100644
--- a/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
+++ b/src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
@@ -49,6 +49,11 @@ namespace Grand.Infrastructure.Configuration
/// </summary>
public bool AllowNonAsciiCharInHeaders { get; set; }
+ /// <summary>
+ /// Gets or sets the maximum allowed size of any request body in bytes
+ /// </summary>
+ public long? MaxRequestBodySize { get; set; }
+
/// <summary>
/// Gets or sets a value indicating - (Serilog) use middleware for smarter HTTP request logging
/// </summary>
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index 6c7cb42c5..4d68396e3 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -30,6 +30,10 @@
//with other HTTP clients.
"AllowNonAsciiCharInHeaders": false,
+ //Gets or sets the maximum allowed size of any request body in bytes
+ //the default value is 30MB
+ "MaxRequestBodySize": null, //max 2147483648
+
//(Serilog) Request logging - The package includes middleware for smarter HTTP request logging.
"UseSerilogRequestLogging": false
},
diff --git a/src/Web/Grand.Web/Program.cs b/src/Web/Grand.Web/Program.cs
index 12698f14a..10226abaa 100644
--- a/src/Web/Grand.Web/Program.cs
+++ b/src/Web/Grand.Web/Program.cs
@@ -3,6 +3,7 @@ using Grand.Web.Common.Startup;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
@@ -51,7 +52,19 @@ if (config.AllowNonAsciiCharInHeaders)
options.ResponseHeaderEncodingSelector = (_) => Encoding.UTF8;
});
}
+if(config.MaxRequestBodySize.HasValue)
+{
+ builder.WebHost.ConfigureKestrel(host =>
+ {
+ host.Limits.MaxRequestBodySize = config.MaxRequestBodySize.Value;
+ });
+ builder.Services.Configure<Microsoft.AspNetCore.Http.Features.FormOptions>(opt =>
+ {
+ opt.MultipartBodyLengthLimit = config.MaxRequestBodySize.Value;
+ });
+
+}
//register task
builder.Services.RegisterTasks();