Updated the Startup.cs to forward headers, hopefully this will help with making sure remote IPs are correctly retrieved.

This commit is contained in:
2021-01-05 21:52:09 -06:00
parent 9d70df80f1
commit fb61c971e9
11 changed files with 79 additions and 14 deletions
+10 -6
View File
@@ -4,12 +4,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SecureCore.Models;
using Microsoft.AspNetCore.HttpOverrides;
using System.Net;
using SecureCore.Services;
namespace SecureCore
@@ -28,6 +24,12 @@ namespace SecureCore
{
services.AddTransient<IDataService, DataService>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
//For more details on this setup consult the docs here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -38,6 +40,8 @@ namespace SecureCore
app.UseDeveloperExceptionPage();
}
app.UseForwardedHeaders();
app.UseRouting();
app.UseAuthorization();