diff --git a/src/admin/Bootstrap.Admin/Pages/Components/DefaultLayoutComponentBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/DefaultLayoutComponentBase.cs
index a98af7eb..27887919 100644
--- a/src/admin/Bootstrap.Admin/Pages/Components/DefaultLayoutComponentBase.cs
+++ b/src/admin/Bootstrap.Admin/Pages/Components/DefaultLayoutComponentBase.cs
@@ -1,9 +1,11 @@
-using Bootstrap.Admin.Pages.Extensions;
-using Bootstrap.Admin.Models;
+using Bootstrap.Admin.Models;
+using Bootstrap.Admin.Pages.Extensions;
using Bootstrap.Admin.Pages.Shared;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
+using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Server;
+using Microsoft.AspNetCore.Http;
using Microsoft.JSInterop;
using System;
using System.Net;
@@ -28,6 +30,12 @@ namespace Bootstrap.Admin.Pages.Components
[Inject]
public NavigationManager? NavigationManager { get; set; }
+ ///
+ /// 获得/设置 组件名字
+ ///
+ [Inject]
+ protected IHttpContextAccessor? HttpContextAccessor { get; set; }
+
///
///
///
@@ -80,6 +88,12 @@ namespace Bootstrap.Admin.Pages.Components
///
protected override async Task OnInitializedAsync()
{
+ // 网页跳转监控
+ if (NavigationManager != null)
+ {
+ NavigationManager.LocationChanged += NavigationManager_LocationChanged;
+ }
+
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (!state.User.Identity.IsAuthenticated)
{
@@ -92,6 +106,12 @@ namespace Bootstrap.Admin.Pages.Components
}
}
+ private void NavigationManager_LocationChanged(object? sender, LocationChangedEventArgs e)
+ {
+ var name = $"/{NavigationManager?.ToBaseRelativePath(e.Location)}";
+ if (HttpContextAccessor != null) HttpContextAccessor.HttpContext?.SaveOnlineUser(name);
+ }
+
///
/// 设置参数方法
///
diff --git a/src/admin/Bootstrap.Admin/Pages/Components/PageContent.cs b/src/admin/Bootstrap.Admin/Pages/Components/PageContent.cs
index 73204e77..169fbeed 100644
--- a/src/admin/Bootstrap.Admin/Pages/Components/PageContent.cs
+++ b/src/admin/Bootstrap.Admin/Pages/Components/PageContent.cs
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
-using Microsoft.AspNetCore.Http;
using System;
namespace Bootstrap.Admin.Pages.Components
@@ -10,12 +9,6 @@ namespace Bootstrap.Admin.Pages.Components
///
public class PageContent : ComponentBase
{
- ///
- /// 获得/设置 组件名字
- ///
- [Inject]
- protected IHttpContextAccessor? HttpContextAccessor { get; set; }
-
///
/// 获得/设置 组件名字
///
@@ -34,8 +27,6 @@ namespace Bootstrap.Admin.Pages.Components
var t = Type.GetType($"Bootstrap.Admin.Pages.Views.{name}");
if (t != null)
{
- // 访问日志
- if (HttpContextAccessor != null) HttpContextAccessor.HttpContext?.SaveOnlineUser($"/Pages/{Name}");
builder.OpenComponent(0, t);
builder.CloseComponent();
diff --git a/src/admin/Bootstrap.Admin/Pages/Extensions/HttpContextExtensions.cs b/src/admin/Bootstrap.Admin/Pages/Extensions/HttpContextExtensions.cs
index 441757d9..44ba4537 100644
--- a/src/admin/Bootstrap.Admin/Pages/Extensions/HttpContextExtensions.cs
+++ b/src/admin/Bootstrap.Admin/Pages/Extensions/HttpContextExtensions.cs
@@ -1,9 +1,9 @@
-using System;
-using System.Net;
using Bootstrap.DataAccess;
using Longbow.Cache;
using Longbow.Web;
using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Net;
namespace Microsoft.AspNetCore.Http
{