- Frondoor Forward Header: https://learn.microsoft.com/en-us/azure/frontdoor/front-door-http-headers-protocol
- Official Doc: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1
- https://endjin.com/blog/2023/01/correctly-configuring-asp-net-core-mvc-authentication-when-hosting-in-azure-container-apps
- https://anthonysimmon.com/securely-reverse-proxy-aspnet-core-web-apps/
- https://github.com/dotnet/aspnetcore/blob/v3.1.32/src/Middleware/HttpOverrides/test/ForwardedHeadersMiddlewareTest.cs#L238-L255
- https://github.com/dotnet/aspnetcore/blob/v3.1.32/src/Middleware/HttpOverrides/test/ForwardedHeadersMiddlewareTest.cs#L754-L775
Created
July 6, 2024 04:39
-
-
Save mildronize/9455124b57fd373da16cf88bf77d49df to your computer and use it in GitHub Desktop.
How to setup ForwardedHeadersMiddleware for .NET Core 3.1 and above
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace IdentityServer | |
{ | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.Configure<ForwardedHeadersOptions>(options => | |
{ | |
options.ForwardedHeaders = ForwardedHeaders.XForwardedHost | ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; | |
options.KnownNetworks.Clear(); | |
options.KnownProxies.Clear(); | |
}); | |
// other middleware configuration... | |
} | |
public void Configure(IApplicationBuilder app) | |
{ | |
app.UseForwardedHeaders(); | |
// other middleware registrations... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment