diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 9d25b0b8..9888019a 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -13,7 +13,7 @@ - + diff --git a/Bootstrap.Admin/BootstrapAdmin.db b/Bootstrap.Admin/BootstrapAdmin.db index a3960713..852930a0 100644 Binary files a/Bootstrap.Admin/BootstrapAdmin.db and b/Bootstrap.Admin/BootstrapAdmin.db differ diff --git a/Bootstrap.Admin/Controllers/AccountController.cs b/Bootstrap.Admin/Controllers/AccountController.cs index f267a050..bea7827a 100644 --- a/Bootstrap.Admin/Controllers/AccountController.cs +++ b/Bootstrap.Admin/Controllers/AccountController.cs @@ -69,11 +69,12 @@ namespace Bootstrap.Admin.Controllers /// internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, IIPLocatorProvider ipLocator, HttpContext context, LoginUser loginUser) { - var agent = new UserAgent(context.Request.Headers["User-Agent"]); + loginUser.UserAgent = context.Request.Headers["User-Agent"]; + var agent = new UserAgent(loginUser.UserAgent); loginUser.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); loginUser.City = ipLocator.Locate(loginUser.Ip); - loginUser.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; - loginUser.OS = $"{agent.OS.Name} {agent.OS.Version}"; + loginUser.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; + loginUser.OS = $"{agent.OS?.Name} {agent.OS?.Version}"; } /// diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs index d96b8ab2..dc654858 100644 --- a/Bootstrap.Admin/Controllers/Api/LogsController.cs +++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs @@ -35,10 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]Log value) { - var agent = new UserAgent(Request.Headers["User-Agent"]); + value.UserAgent = Request.Headers["User-Agent"]; + var agent = new UserAgent(value.UserAgent); value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); - value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; - value.OS = $"{agent.OS.Name} {agent.OS.Version}"; + value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; + value.OS = $"{agent.OS?.Name} {agent.OS?.Version}"; value.City = ipLocator.Locate(value.Ip); value.UserName = User.Identity.Name; return LogHelper.Save(value); diff --git a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index 5c17bcaa..e080791c 100644 --- a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -14,7 +14,7 @@ - + diff --git a/Bootstrap.Client/Bootstrap.Client.csproj b/Bootstrap.Client/Bootstrap.Client.csproj index 3eead6d4..fab9b24d 100644 --- a/Bootstrap.Client/Bootstrap.Client.csproj +++ b/Bootstrap.Client/Bootstrap.Client.csproj @@ -9,7 +9,7 @@ - + diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 4f35d374..8c109e2a 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -15,7 +15,7 @@ - + diff --git a/Bootstrap.DataAccess/Helper/TraceHelper.cs b/Bootstrap.DataAccess/Helper/TraceHelper.cs index d85bec1c..1c54eaa4 100644 --- a/Bootstrap.DataAccess/Helper/TraceHelper.cs +++ b/Bootstrap.DataAccess/Helper/TraceHelper.cs @@ -30,7 +30,8 @@ namespace Bootstrap.DataAccess City = v.Location, Browser = v.Browser, OS = v.OS, - UserName = v.UserName + UserName = v.UserName, + UserAgent = v.UserAgent }); } } diff --git a/Bootstrap.DataAccess/Log.cs b/Bootstrap.DataAccess/Log.cs index 3490f127..0aa20fc3 100644 --- a/Bootstrap.DataAccess/Log.cs +++ b/Bootstrap.DataAccess/Log.cs @@ -13,8 +13,8 @@ namespace Bootstrap.DataAccess /// public string CRUD { get; set; } - /// - /// 获得/设置 请求数据 + /// + /// 获得/设置 请求数据 /// public string RequestData { get; set; } diff --git a/Bootstrap.DataAccess/LoginUser.cs b/Bootstrap.DataAccess/LoginUser.cs index ef1cd124..ae2f4b65 100644 --- a/Bootstrap.DataAccess/LoginUser.cs +++ b/Bootstrap.DataAccess/LoginUser.cs @@ -50,6 +50,11 @@ namespace Bootstrap.DataAccess /// public string Result { get; set; } + /// + /// + /// + public string UserAgent { get; set; } + /// /// /// diff --git a/Bootstrap.DataAccess/Trace.cs b/Bootstrap.DataAccess/Trace.cs index 003197bc..7bd2190a 100644 --- a/Bootstrap.DataAccess/Trace.cs +++ b/Bootstrap.DataAccess/Trace.cs @@ -49,6 +49,11 @@ namespace Bootstrap.DataAccess /// public string RequestUrl { get; set; } + /// + /// + /// + public string UserAgent { get; set; } + /// /// 保存访问历史记录 /// diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql index 7f224b37..b8399279 100644 --- a/DatabaseScripts/Install.sql +++ b/DatabaseScripts/Install.sql @@ -273,6 +273,7 @@ CREATE TABLE [dbo].[Logs]( [City] [nvarchar](50) NULL, [RequestUrl] [nvarchar](500) NOT NULL, [RequestData] [nvarchar](500) NULL, + [UserAgent] [varchar](2000) NULL, CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED ( [ID] ASC @@ -499,6 +500,7 @@ CREATE TABLE [dbo].[LoginLogs]( [Browser] [varchar](50) NULL, [City] [nvarchar](50) NULL, [Result] [nvarchar](50) NOT NULL, + [UserAgent] [varchar](2000) NULL, CONSTRAINT [PK_LoginLogs] PRIMARY KEY CLUSTERED ( [ID] ASC @@ -556,6 +558,7 @@ CREATE TABLE [dbo].[Traces]( [OS] [varchar](50) NULL, [City] [nvarchar](50) NULL, [RequestUrl] [nvarchar](500) NOT NULL, + [UserAgent] [varchar](2000) NULL, CONSTRAINT [PK_Traces] PRIMARY KEY CLUSTERED ( [ID] ASC diff --git a/DatabaseScripts/MySQL/install.sql b/DatabaseScripts/MySQL/install.sql index 9e94fa4f..1ba142f8 100644 --- a/DatabaseScripts/MySQL/install.sql +++ b/DatabaseScripts/MySQL/install.sql @@ -87,7 +87,8 @@ CREATE TABLE Logs( OS VARCHAR (50) NULL, City VARCHAR (50) NULL, RequestUrl VARCHAR (500) NOT NULL, - RequestData VARCHAR (500) NULL + RequestData VARCHAR (500) NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE `Groups`( @@ -158,7 +159,8 @@ CREATE TABLE LoginLogs( OS VARCHAR (50) NULL, Browser VARCHAR (50) NULL, City VARCHAR (50) NULL, - Result VARCHAR (50) NOT NULL + Result VARCHAR (50) NOT NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE ResetUsers( @@ -177,5 +179,6 @@ CREATE TABLE Traces( Browser VARCHAR (50), OS VARCHAR (50), City VARCHAR (50), - RequestUrl VARCHAR (500) NOT NULL + RequestUrl VARCHAR (500) NOT NULL, + UserAgent VARCHAR (2000) NULL ); \ No newline at end of file diff --git a/DatabaseScripts/Postgresql/install.sql b/DatabaseScripts/Postgresql/install.sql index 00935942..0a877dad 100644 --- a/DatabaseScripts/Postgresql/install.sql +++ b/DatabaseScripts/Postgresql/install.sql @@ -87,7 +87,8 @@ CREATE TABLE Logs( OS VARCHAR (50) NULL, City VARCHAR (50) NULL, RequestUrl VARCHAR (500) NOT NULL, - RequestData VARCHAR (500) NULL + RequestData VARCHAR (500) NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE Groups( @@ -158,7 +159,8 @@ CREATE TABLE RejectUsers( OS VARCHAR (50) NULL, Browser VARCHAR (50) NULL, City VARCHAR (50) NULL, - Result VARCHAR (50) NOT NULL + Result VARCHAR (50) NOT NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE ResetUsers( @@ -177,5 +179,6 @@ CREATE TABLE Traces( Browser VARCHAR (50), OS VARCHAR (50), City VARCHAR (50), - RequestUrl VARCHAR (500) NOT NULL + RequestUrl VARCHAR (500) NOT NULL, + UserAgent VARCHAR (2000) NULL ); \ No newline at end of file diff --git a/DatabaseScripts/SQLite/Install.sql b/DatabaseScripts/SQLite/Install.sql index b47893c8..cc11e308 100644 --- a/DatabaseScripts/SQLite/Install.sql +++ b/DatabaseScripts/SQLite/Install.sql @@ -87,7 +87,8 @@ CREATE TABLE Logs( OS VARCHAR (50) NULL, City VARCHAR (50) NULL, RequestUrl VARCHAR (500) NOT NULL, - RequestData VARCHAR (500) NULL + RequestData VARCHAR (500) NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE Groups( @@ -158,7 +159,8 @@ CREATE TABLE LoginLogs( OS VARCHAR (50) NULL, Browser VARCHAR (50) NULL, City VARCHAR (50) NULL, - Result VARCHAR (50) NOT NULL + Result VARCHAR (50) NOT NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE ResetUsers( @@ -177,5 +179,6 @@ CREATE TABLE Traces( Browser VARCHAR (50), OS VARCHAR (50), City VARCHAR (50), - RequestUrl VARCHAR (500) NOT NULL + RequestUrl VARCHAR (500) NOT NULL, + UserAgent VARCHAR (2000) ); \ No newline at end of file diff --git a/UnitTest/DB/UnitTest.db b/UnitTest/DB/UnitTest.db index 349fb9ed..b259bfe5 100644 Binary files a/UnitTest/DB/UnitTest.db and b/UnitTest/DB/UnitTest.db differ