From d319ec4156ab862691a828fb7665d993bda05ed4 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 14 May 2021 18:57:53 +0800 Subject: [PATCH 1/2] Get the client IP address from the reverse proxy --- .../AuthIdentityServerModule.cs | 20 ++----------------- .../AuthServer.Host/AuthServer.Host.csproj | 1 + .../BackendAdminHostModule.cs | 18 ++--------------- ...NGYUN.Abp.BackendAdmin.HttpApi.Host.csproj | 1 + .../ApiGatewayHttpApiHostModule.cs | 18 +++-------------- .../LINGYUN.ApiGateway.HttpApi.Host.csproj | 1 + ...AbpIdentityServerAdminHttpApiHostModule.cs | 19 ++---------------- ...UN.Abp.IdentityServer4.HttpApi.Host.csproj | 1 + ...LocalizationManagementHttpApiHostModule.cs | 4 +++- ...LocalizationManagement.HttpApi.Host.csproj | 1 + .../AbpMessageServiceHttpApiHostModule.cs | 16 ++------------- ...YUN.Abp.MessageService.HttpApi.Host.csproj | 1 + .../AppPlatformHttpApiHostModule.cs | 19 ++---------------- .../LINGYUN.Platform.HttpApi.Host.csproj | 1 + 14 files changed, 23 insertions(+), 98 deletions(-) diff --git a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs index a3e681ff0..0df1a0043 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs +++ b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.Identity.EntityFrameworkCore; using LINGYUN.Abp.IdentityServer; @@ -11,7 +12,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; @@ -23,15 +23,12 @@ using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Account.Localization; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.Auditing; @@ -46,7 +43,6 @@ using Volo.Abp.Identity; using Volo.Abp.IdentityServer; using Volo.Abp.IdentityServer.Jwt; using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -63,8 +59,6 @@ namespace AuthServer.Host [DependsOn( typeof(AbpAccountWebIdentityServerModule), typeof(AbpAccountApplicationModule), - typeof(AbpAspNetCoreMvcUiMultiTenancyModule), - typeof(AbpAspNetCoreMvcModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAutofacModule), typeof(AbpCachingStackExchangeRedisModule), @@ -81,6 +75,7 @@ namespace AuthServer.Host typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpTenantManagementEntityFrameworkCoreModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCAPEventBusModule), typeof(AbpAliyunSmsModule) @@ -134,15 +129,6 @@ namespace AuthServer.Host var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = context.Services.GetConfiguration(); - // 请求代理配置 - Configure(options => - { - configuration.GetSection("App:Forwarded").Bind(options); - // 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器 - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - Configure(options => { options.UseMySQL(); @@ -300,8 +286,6 @@ namespace AuthServer.Host var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); - // 从请求头中解析真实的客户机连接信息 - app.UseForwardedHeaders(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj index b724a7646..2283c721a 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj +++ b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj @@ -52,6 +52,7 @@ + diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs index 5ba3365de..60226d991 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs @@ -1,5 +1,6 @@ using DotNetCore.CAP; using LINGYUN.Abp.Aliyun.SettingManagement; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.Auditing; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; @@ -17,7 +18,6 @@ using LINGYUN.Abp.TenantManagement; using LINGYUN.Abp.WeChat.SettingManagement; using LINGYUN.ApiGateway; using LINGYUN.Platform; -using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; @@ -30,8 +30,6 @@ using Microsoft.OpenApi.Models; using StackExchange.Redis; using System; using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; @@ -52,7 +50,6 @@ using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.Localization; using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -65,7 +62,6 @@ using Volo.Abp.Security.Encryption; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.Threading; -using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Abp.BackendAdmin @@ -110,6 +106,7 @@ namespace LINGYUN.Abp.BackendAdmin typeof(AbpAliyunSmsModule), typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpAutofacModule) )] public class BackendAdminHostModule : AbpModule @@ -135,15 +132,6 @@ namespace LINGYUN.Abp.BackendAdmin var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = hostingEnvironment.BuildConfiguration(); - // 请求代理配置 - Configure(options => - { - configuration.GetSection("App:Forwarded").Bind(options); - // 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器 - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - // 配置Ef Configure(options => { @@ -345,8 +333,6 @@ namespace LINGYUN.Abp.BackendAdmin public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); - // 代理的中间件应放在其他中间件之前 - app.UseForwardedHeaders(); // http调用链 app.UseCorrelationId(); // 虚拟文件系统 diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj index 21d525180..d9b1ead35 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj @@ -64,6 +64,7 @@ + diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs index 038c1612c..1632c3034 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.ApiGateway.EntityFrameworkCore; @@ -25,6 +26,7 @@ using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; +using Volo.Abp.Json; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -34,10 +36,6 @@ using Volo.Abp.Security.Encryption; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.Threading; -using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; -using System.Text.Encodings.Web; -using System.Text.Unicode; namespace LINGYUN.ApiGateway { @@ -53,6 +51,7 @@ namespace LINGYUN.ApiGateway typeof(AbpCAPEventBusModule), typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpAutofacModule) )] public class ApiGatewayHttpApiHostModule : AbpModule @@ -77,15 +76,6 @@ namespace LINGYUN.ApiGateway var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = hostingEnvironment.BuildConfiguration(); - // 请求代理配置 - Configure(options => - { - configuration.GetSection("App:Forwarded").Bind(options); - // 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器 - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - // 配置Ef Configure(options => { @@ -228,8 +218,6 @@ namespace LINGYUN.ApiGateway { var app = context.GetApplicationBuilder(); var configuration = context.GetConfiguration(); - - app.UseForwardedHeaders(); // http调用链 app.UseCorrelationId(); // 虚拟文件系统 diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj index 5573e12c1..c12a36a31 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj @@ -40,6 +40,7 @@ + diff --git a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs index 1d11cec96..6c9eef45c 100644 --- a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs +++ b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs @@ -1,11 +1,11 @@ using DotNetCore.CAP; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.Sms.Aliyun; -using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; @@ -19,8 +19,6 @@ using Microsoft.OpenApi.Models; using StackExchange.Redis; using System; using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; @@ -35,9 +33,7 @@ using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.Identity.Localization; -using Volo.Abp.IdentityServer.Localization; using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -47,7 +43,6 @@ using Volo.Abp.Security.Claims; using Volo.Abp.Security.Encryption; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.EntityFrameworkCore; -using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Abp.IdentityServer4 @@ -74,6 +69,7 @@ namespace LINGYUN.Abp.IdentityServer4 typeof(AbpAliyunSmsModule), typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpAutofacModule) )] public class AbpIdentityServerAdminHttpApiHostModule : AbpModule @@ -104,15 +100,6 @@ namespace LINGYUN.Abp.IdentityServer4 var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = hostingEnvironment.BuildConfiguration(); - // 请求代理配置 - Configure(options => - { - configuration.GetSection("App:Forwarded").Bind(options); - // 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器 - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - // 配置Ef Configure(options => { @@ -309,8 +296,6 @@ namespace LINGYUN.Abp.IdentityServer4 public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); - - app.UseForwardedHeaders(); // http调用链 app.UseCorrelationId(); // 虚拟文件系统 diff --git a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj index 2cc3770cb..ab8c595b6 100644 --- a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj +++ b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj @@ -54,6 +54,7 @@ + diff --git a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs index 0bf2c7835..9b4a52d95 100644 --- a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs +++ b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; @@ -55,6 +56,7 @@ namespace LINGYUN.Abp.LocalizationManagement typeof(AbpCAPEventBusModule), typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpAutofacModule) )] public class AbpLocalizationManagementHttpApiHostModule : AbpModule @@ -233,7 +235,7 @@ namespace LINGYUN.Abp.LocalizationManagement // http调用链 app.UseCorrelationId(); // 虚拟文件系统 - app.UseVirtualFiles(); + app.UseStaticFiles(); // 本地化 app.UseAbpRequestLocalization(); // 多租户 diff --git a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj index 1009ba6f1..ed089aa3c 100644 --- a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj +++ b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj @@ -32,6 +32,7 @@ + diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs index 4dded8212..716ae3ba6 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs @@ -1,5 +1,6 @@ using DotNetCore.CAP; using Hangfire; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json; using LINGYUN.Abp.BackgroundJobs.Hangfire; using LINGYUN.Abp.EventBus.CAP; @@ -28,8 +29,6 @@ using StackExchange.Redis; using System; using System.Linq; using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; @@ -39,7 +38,6 @@ using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -72,6 +70,7 @@ namespace LINGYUN.Abp.MessageService typeof(AbpHangfireMySqlStorageModule), typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpAutofacModule) )] public class AbpMessageServiceHttpApiHostModule : AbpModule @@ -99,15 +98,6 @@ namespace LINGYUN.Abp.MessageService var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = hostingEnvironment.BuildConfiguration(); - // 请求代理配置 - Configure(options => - { - configuration.GetSection("App:Forwarded").Bind(options); - // 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器 - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - // 配置Ef Configure(options => { @@ -306,8 +296,6 @@ namespace LINGYUN.Abp.MessageService public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); - - app.UseForwardedHeaders(); // http调用链 app.UseCorrelationId(); // 虚拟文件系统 diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj index 121beff37..bc15481c5 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj @@ -42,6 +42,7 @@ + diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs index 25597e390..74eb29088 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; @@ -12,8 +13,6 @@ using LINGYUN.Abp.OssManagement.FileSystem.ImageSharp; using LINGYUN.Abp.OssManagement.SettingManagement; using LINGYUN.Platform.EntityFrameworkCore; using LINGYUN.Platform.HttpApi; -using LINGYUN.Platform.Localization; -using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; @@ -28,8 +27,6 @@ using StackExchange.Redis; using System; using System.IO; using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; @@ -47,7 +44,6 @@ using Volo.Abp.FeatureManagement.EntityFrameworkCore; using Volo.Abp.Http.Client.IdentityModel.Web; using Volo.Abp.Identity; using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -57,7 +53,6 @@ using Volo.Abp.Security.Encryption; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.Threading; -using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Platform @@ -90,6 +85,7 @@ namespace LINGYUN.Platform // typeof(AbpFeaturesValidationRedisClientModule),// 当需要客户端特性限制时取消注释此模块 typeof(AbpDbFinderMultiTenancyModule), typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpAspNetCoreHttpOverridesModule), typeof(AbpAutofacModule) )] public class AppPlatformHttpApiHostModule : AbpModule @@ -115,15 +111,6 @@ namespace LINGYUN.Platform var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = hostingEnvironment.BuildConfiguration(); - // 请求代理配置 - Configure(options => - { - configuration.GetSection("App:Forwarded").Bind(options); - // 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器 - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - // 配置Ef Configure(options => { @@ -310,8 +297,6 @@ namespace LINGYUN.Platform { var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); - - app.UseForwardedHeaders(); // http调用链 app.UseCorrelationId(); // 虚拟文件系统 diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj index a7944df88..b01d148ae 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj @@ -51,6 +51,7 @@ + From 9ab462a9f6a541a951ed6e365a73e9c437f69136 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 14 May 2021 19:00:47 +0800 Subject: [PATCH 2/2] Get the client IP address from the reverse proxy --- .../RequestForwardedHeaderWebClientInfoProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs index 9c2ae872b..3ef5dc6cf 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs @@ -32,7 +32,7 @@ namespace LINGYUN.Abp.AspNetCore.WebClientInfo if (requestHeaders != null && requestHeaders.TryGetValue(Options.ForwardedForHeaderName, out StringValues headers) == true) { - if (StringValues.IsNullOrEmpty(headers)) + if (!StringValues.IsNullOrEmpty(headers)) { return headers.Last(); }