From 58f8b23b7ccfd714cdc2988267c8af98ea77834f Mon Sep 17 00:00:00 2001
From: Diego <2248356998@qq.com>
Date: Tue, 22 Apr 2025 11:45:14 +0800
Subject: [PATCH] build:10.5.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fix: 反向代理正确获取客户端IP
refactor: 添加demo站点域名
---
README.md | 5 ++++-
README.zh-CN.md | 2 +-
.../Aop/OperDescAttribute.cs | 2 +-
.../Services/AppService/AppService.cs | 2 +-
.../Services/AppService/HybridAppService.cs | 4 ++--
.../Services/AppService/IAppService.cs | 2 +-
.../Services/Auth/AuthService.cs | 4 ++--
src/Admin/ThingsGateway.AdminServer/Program/Startup.cs | 2 +-
.../AspNetCore/Extensions/HttpContextExtensions.cs | 2 +-
src/Directory.Build.props | 4 ++--
.../Controller/ControlController.cs | 3 ++-
src/Plugin/ThingsGateway.Debug.Razor/Pages/Index.razor | 2 +-
src/ThingsGateway.Photino/Startup.cs | 2 +-
src/ThingsGateway.Server/Program/Startup.cs | 3 ++-
src/ThingsGateway.Server/Properties/launchSettings.json | 6 +++---
src/ThingsGateway.Server/appsettings.Development.json | 1 -
src/Upgrade/ThingsGateway.UpgradeServer/Program/Startup.cs | 2 +-
src/Version.props | 2 +-
18 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
index 88511286c..8828a7e09 100644
--- a/README.md
+++ b/README.md
@@ -20,11 +20,14 @@ A cross-platform, high-performance edge data collection gateway based on net9.
## Demo
-[Demo](http://47.119.161.158:5000/)
+[Demo](https://demo.thingsgateway.cn/)
+
Account: **SuperAdmin**
+
Password: **111111**
+
**In the upper-right corner, switch to the IoT Gateway module in the personal popup box**
diff --git a/README.zh-CN.md b/README.zh-CN.md
index c85a0c849..19850990c 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -13,7 +13,7 @@
## 演示
-[ThingsGateway演示地址](http://47.119.161.158:5000/)
+[ThingsGateway演示地址](https://demo.thingsgateway.cn/)
账户 : **SuperAdmin**
diff --git a/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs b/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs
index e638c3e51..93c301c26 100644
--- a/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs
+++ b/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs
@@ -137,7 +137,7 @@ public sealed class OperDescAttribute : MoAttribute
Name = (localizerType == null ? App.CreateLocalizerByType(typeof(OperDescAttribute)) : App.CreateLocalizerByType(localizerType))![Description],
Category = LogCateGoryEnum.Operate,
ExeStatus = true,
- OpIp = AppService?.RemoteIpAddress?.MapToIPv4()?.ToString() ?? string.Empty,
+ OpIp = AppService?.RemoteIpAddress ?? string.Empty,
OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
OpTime = DateTime.Now,
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs
index 5d298b4a3..1d387370e 100644
--- a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs
@@ -72,7 +72,7 @@ public class AppService : IAppService
}
public ClaimsPrincipal? User => App.User;
- public IPAddress? RemoteIpAddress => App.HttpContext?.Connection?.RemoteIpAddress;
+ public string? RemoteIpAddress => App.HttpContext?.GetRemoteIpAddressToIPv4();
public int LocalPort => App.HttpContext.Connection.LocalPort;
}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/HybridAppService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/HybridAppService.cs
index c7c34daae..048138866 100644
--- a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/HybridAppService.cs
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/HybridAppService.cs
@@ -24,7 +24,7 @@ public class HybridAppService : IAppService
{
var str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0";
ClientInfo = Parser.GetDefault().Parse(str);
- RemoteIpAddress = IPAddress.Parse("127.0.0.1");
+ RemoteIpAddress = "127.0.0.1";
}
public ClientInfo? ClientInfo { get; }
@@ -56,7 +56,7 @@ public class HybridAppService : IAppService
}
}
- public IPAddress? RemoteIpAddress { get; }
+ public string? RemoteIpAddress { get; }
public string GetReturnUrl(string returnUrl)
{
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs
index 5c897e049..474b9a202 100644
--- a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs
@@ -31,7 +31,7 @@ public interface IAppService
///
/// RemoteIpAddress
///
- public IPAddress? RemoteIpAddress { get; }
+ public string? RemoteIpAddress { get; }
///
/// GetReturnUrl
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs
index a37c77ac6..69bc5609d 100644
--- a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs
@@ -105,7 +105,7 @@ public class AuthService : IAuthService
{
var loginEvent = new LoginEvent
{
- Ip = _appService.RemoteIpAddress?.MapToIPv4()?.ToString(),
+ Ip = _appService.RemoteIpAddress,
SysUser = userinfo,
VerificatId = verificatId
};
@@ -236,7 +236,7 @@ public class AuthService : IAuthService
//登录事件参数
var logingEvent = new LoginEvent
{
- Ip = _appService.RemoteIpAddress?.MapToIPv4()?.ToString(),
+ Ip = _appService.RemoteIpAddress,
Device = App.GetService().ClientInfo?.OS?.ToString(),
Expire = expire,
SysUser = sysUser,
diff --git a/src/Admin/ThingsGateway.AdminServer/Program/Startup.cs b/src/Admin/ThingsGateway.AdminServer/Program/Startup.cs
index a545472a9..998fe78a8 100644
--- a/src/Admin/ThingsGateway.AdminServer/Program/Startup.cs
+++ b/src/Admin/ThingsGateway.AdminServer/Program/Startup.cs
@@ -298,9 +298,9 @@ public class Startup : AppStartup
public void Use(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
{
var app = (WebApplication)applicationBuilder;
+ app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All, KnownNetworks = { }, KnownProxies = { } });
app.UseBootstrapBlazor();
- app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All });
// 启用本地化
var option = app.Services.GetService>();
diff --git a/src/Admin/ThingsGateway.Furion/AspNetCore/Extensions/HttpContextExtensions.cs b/src/Admin/ThingsGateway.Furion/AspNetCore/Extensions/HttpContextExtensions.cs
index d0b7f4645..040d8534d 100644
--- a/src/Admin/ThingsGateway.Furion/AspNetCore/Extensions/HttpContextExtensions.cs
+++ b/src/Admin/ThingsGateway.Furion/AspNetCore/Extensions/HttpContextExtensions.cs
@@ -106,7 +106,7 @@ public static class HttpContextExtensions
///
/// 是否优先取 X-Forwarded-For
///
- public static string GetRemoteIpAddressToIPv4(this HttpContext context, bool xff = false)
+ public static string GetRemoteIpAddressToIPv4(this HttpContext context, bool xff = true)
{
var ipv4 = context.Connection.RemoteIpAddress?.MapToIPv4()?.ToString();
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index b9eefbf59..a8c0cc98a 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -1,8 +1,8 @@
- 10.4.22
- 10.4.22
+ 10.5.1
+ 10.5.1
2.1.7
diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Controller/ControlController.cs b/src/Gateway/ThingsGateway.Gateway.Application/Controller/ControlController.cs
index 039ed3a5f..42291dd2d 100644
--- a/src/Gateway/ThingsGateway.Gateway.Application/Controller/ControlController.cs
+++ b/src/Gateway/ThingsGateway.Gateway.Application/Controller/ControlController.cs
@@ -13,6 +13,7 @@ using BootstrapBlazor.Components;
using Mapster;
using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
@@ -139,7 +140,7 @@ public class ControlController : ControllerBase
}
}
- return await GlobalData.RpcService.InvokeDeviceMethodAsync($"WebApi-{UserManager.UserAccount}-{App.HttpContext.Connection.RemoteIpAddress.MapToIPv4()}", deviceDatas).ConfigureAwait(false);
+ return await GlobalData.RpcService.InvokeDeviceMethodAsync($"WebApi-{UserManager.UserAccount}-{App.HttpContext?.GetRemoteIpAddressToIPv4()}", deviceDatas).ConfigureAwait(false);
}
diff --git a/src/Plugin/ThingsGateway.Debug.Razor/Pages/Index.razor b/src/Plugin/ThingsGateway.Debug.Razor/Pages/Index.razor
index 6252dde2d..150887b51 100644
--- a/src/Plugin/ThingsGateway.Debug.Razor/Pages/Index.razor
+++ b/src/Plugin/ThingsGateway.Debug.Razor/Pages/Index.razor
@@ -20,7 +20,7 @@
演示
- ThingsGateway演示地址
+ ThingsGateway演示地址
账户 : SuperAdmin
密码 : 111111
右上角个人弹出框中,切换到物联网关模块
diff --git a/src/ThingsGateway.Photino/Startup.cs b/src/ThingsGateway.Photino/Startup.cs
index 18ad08378..d2a129706 100644
--- a/src/ThingsGateway.Photino/Startup.cs
+++ b/src/ThingsGateway.Photino/Startup.cs
@@ -280,9 +280,9 @@ public class Startup : AppStartup
public void Use(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
{
var app = (WebApplication)applicationBuilder;
+ app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All, KnownNetworks = { }, KnownProxies = { } });
app.UseBootstrapBlazor();
- app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All });
// 启用本地化
var option = app.Services.GetService>();
diff --git a/src/ThingsGateway.Server/Program/Startup.cs b/src/ThingsGateway.Server/Program/Startup.cs
index 465ab1619..4c53a9aa1 100644
--- a/src/ThingsGateway.Server/Program/Startup.cs
+++ b/src/ThingsGateway.Server/Program/Startup.cs
@@ -298,9 +298,10 @@ public class Startup : AppStartup
public void Use(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
{
var app = (WebApplication)applicationBuilder;
+ app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All, KnownNetworks = { }, KnownProxies = { } });
+
app.UseBootstrapBlazor();
- app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All });
// 启用本地化
var option = app.Services.GetService>();
diff --git a/src/ThingsGateway.Server/Properties/launchSettings.json b/src/ThingsGateway.Server/Properties/launchSettings.json
index 138561ef0..b622a6f01 100644
--- a/src/ThingsGateway.Server/Properties/launchSettings.json
+++ b/src/ThingsGateway.Server/Properties/launchSettings.json
@@ -7,7 +7,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
- "applicationUrl": "http://localhost:5000"
+ "applicationUrl": "http://*:5000"
},
"demo": {
"commandName": "Project",
@@ -16,7 +16,7 @@
"ASPNETCORE_ENVIRONMENT": "Demo"
},
"dotnetRunMessages": true,
- "applicationUrl": "http://localhost:5000"
+ "applicationUrl": "http://*:5000"
},
"IIS Express": {
@@ -32,7 +32,7 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
- "applicationUrl": "http://localhost:59494/",
+ "applicationUrl": "http://*:59494/",
"sslPort": 44372
}
}
diff --git a/src/ThingsGateway.Server/appsettings.Development.json b/src/ThingsGateway.Server/appsettings.Development.json
index 6ed2d3a6a..71400dd0e 100644
--- a/src/ThingsGateway.Server/appsettings.Development.json
+++ b/src/ThingsGateway.Server/appsettings.Development.json
@@ -1,5 +1,4 @@
{
- "urls": "http://*:5000",
"ConfigurationScanDirectories": [ "Configuration", "" ], // 扫描配置文件json文件夹(自动合并该文件夹里面所有json文件)
"IgnoreConfigurationFiles": [ "" ],
diff --git a/src/Upgrade/ThingsGateway.UpgradeServer/Program/Startup.cs b/src/Upgrade/ThingsGateway.UpgradeServer/Program/Startup.cs
index 632808fc1..3545b99f9 100644
--- a/src/Upgrade/ThingsGateway.UpgradeServer/Program/Startup.cs
+++ b/src/Upgrade/ThingsGateway.UpgradeServer/Program/Startup.cs
@@ -304,9 +304,9 @@ public class Startup : AppStartup
public void Use(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)
{
var app = (WebApplication)applicationBuilder;
+ app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All, KnownNetworks = { }, KnownProxies = { } });
app.UseBootstrapBlazor();
- app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All });
// 启用本地化
var option = app.Services.GetService>();
diff --git a/src/Version.props b/src/Version.props
index 96a3e435f..e83d9f4e5 100644
--- a/src/Version.props
+++ b/src/Version.props
@@ -1,6 +1,6 @@
- 10.4.22
+ 10.5.1