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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Add new settings ForceUseHTTPS
supportcf087e35c333
diff --git a/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs b/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.csindex b1432e84a..c02c66842 100644--- a/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs+++ b/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs@@ -7,6 +7,11 @@/// </summary>public bool UseForwardedHeaders { get; set; }+ /// <summary>+ /// Gets or sets a value indicating whether to force use https+ /// </summary>+ public bool ForceUseHTTPS { get; set; }+/// <summary>/// Gets or sets a value for allowedHosts, is used for host filtering to bind your app to specific hostnames/// </summary>diff --git a/src/Web/Grand.Web.Common/Startup/ForwardedHeadersStartup.cs b/src/Web/Grand.Web.Common/Startup/ForwardedHeadersStartup.csindex a833cfa45..4840163c4 100644--- a/src/Web/Grand.Web.Common/Startup/ForwardedHeadersStartup.cs+++ b/src/Web/Grand.Web.Common/Startup/ForwardedHeadersStartup.cs@@ -34,7 +34,14 @@ namespace Grand.Web.Common.Startupvar serviceProvider = application.ApplicationServices;var securityConfig = serviceProvider.GetRequiredService<SecurityConfig>();-+ if (securityConfig.ForceUseHTTPS)+ {+ application.Use((context, next) =>+ {+ context.Request.Scheme = "https";+ return next(context);+ });+ }if (securityConfig.UseForwardedHeaders)application.UseGrandForwardedHeaders();diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.jsonindex c74665694..ae0ee6cdb 100644--- a/src/Web/Grand.Web/App_Data/appsettings.json+++ b/src/Web/Grand.Web/App_Data/appsettings.json@@ -50,6 +50,9 @@//Use a reverse proxy server - more information you can find at: https://docs.microsoft.com/en-US/aspnet/core/host-and-deploy/linux-nginx"UseForwardedHeaders": false,+ //In some cases, it might not be possible to add forwarded headers to the requests proxied to the app.+ "ForceUseHTTPS": false,+//AllowedHosts, is used for host filtering to bind your app to specific hostnames"AllowedHosts": "*",