Skip to content

Instantly share code, notes, and snippets.

@mildronize
Created July 6, 2024 04:39
Show Gist options
  • Save mildronize/9455124b57fd373da16cf88bf77d49df to your computer and use it in GitHub Desktop.
Save mildronize/9455124b57fd373da16cf88bf77d49df to your computer and use it in GitHub Desktop.
How to setup ForwardedHeadersMiddleware for .NET Core 3.1 and above
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