53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
#define FIRST // FIRST
|
|
#if NEVER
|
|
#elif FIRST
|
|
// <snippet_1>
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddAuthentication();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
|
{
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
|
});
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.MapGet("/", () => "Hello ForwardedHeadersOptions!");
|
|
|
|
app.Run();
|
|
// </snippet_1>
|
|
#else
|
|
// <snippet_all>
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using System.Net;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Configure forwarded headers
|
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
|
{
|
|
options.KnownProxies.Add(IPAddress.Parse("10.0.0.100"));
|
|
});
|
|
|
|
builder.Services.AddAuthentication();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
|
{
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
|
});
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.MapGet("/", () => "10.0.0.100");
|
|
|
|
app.Run();
|
|
// </snippet_all>
|
|
#endif
|