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.

Roslyn script - add sample code - with use StartupApplication

KrzysztofPajak11a05ef62b0a
diff --git a/src/Web/Grand.Web/Roslyn/UseForwardedHeaders.csx b/src/Web/Grand.Web/Roslyn/UseForwardedHeaders.csx
new file mode 100644
index 000000000..272498d51
--- /dev/null
+++ b/src/Web/Grand.Web/Roslyn/UseForwardedHeaders.csx
@@ -0,0 +1,35 @@
+#! "net5.0"
+#r "Grand.Infrastructure"
+#r "Grand.Web"
+
+using Grand.Infrastructure;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using System.Net;
+using System;
+
+/* Sample code to Forwarded Headers Middleware */
+/* More info you can find here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-5.0 */
+
+public class StartupApplication : IStartupApplication
+{
+ public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
+ {
+ }
+ public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)
+ {
+ var forwardedHeadersOptions = new ForwardedHeadersOptions
+ {
+ ForwardLimit = 2,
+ ForwardedForHeaderName = "X-Forwarded-For-My-Custom-Header-Name"
+ };
+ forwardedHeadersOptions.KnownProxies.Add(IPAddress.Parse("127.0.0.1"));
+
+ application.UseForwardedHeaders(forwardedHeadersOptions);
+
+ }
+ public int Priority => -19;
+ public bool BeforeConfigure => false;
+}