From aabb94ac550270c5878dbe6908adbcdfef41cc66 Mon Sep 17 00:00:00 2001 From: DCTewi Date: Thu, 24 Jun 2021 02:05:22 +0800 Subject: [PATCH] Remove: IP info in log nginx hide them --- .../Middlewares/AccessProtectionMiddleware.cs | 6 +++--- VirtualGroupEx.Server/Middlewares/PostLoginMiddleware.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VirtualGroupEx.Server/Middlewares/AccessProtectionMiddleware.cs b/VirtualGroupEx.Server/Middlewares/AccessProtectionMiddleware.cs index cbe3a77..e507c93 100644 --- a/VirtualGroupEx.Server/Middlewares/AccessProtectionMiddleware.cs +++ b/VirtualGroupEx.Server/Middlewares/AccessProtectionMiddleware.cs @@ -32,12 +32,12 @@ public Task Invoke(HttpContext httpContext, if (path.StartsWith("/_blazor") || path.EndsWith(".css") || path.EndsWith(".js")) { logger.LogTrace( - $"IP[{httpContext.Connection.RemoteIpAddress?.ToString()}] try to access [{path}]"); + $"User[{httpContext?.User?.Identity?.Name ?? ""}] try to access [{path}]"); } else { logger.LogInformation( - $"IP[{httpContext.Connection.RemoteIpAddress?.ToString()}] try to access [{path}]"); + $"User[{httpContext?.User?.Identity?.Name ?? ""}] try to access [{path}]"); var isSigned = signInManager.IsSignedIn(httpContext.User); @@ -52,7 +52,7 @@ public Task Invoke(HttpContext httpContext, if (!options.Whitelist.Contains(path)) { logger.LogInformation( - $"IP[{httpContext.Connection.RemoteIpAddress?.ToString()}] User[{httpContext?.User?.Identity?.Name}] access denied for [{path}]"); + $"User[{httpContext?.User?.Identity?.Name ?? ""}] access denied for [{path}]"); httpContext.Response.Redirect(options.AuthPath); diff --git a/VirtualGroupEx.Server/Middlewares/PostLoginMiddleware.cs b/VirtualGroupEx.Server/Middlewares/PostLoginMiddleware.cs index deb1289..e105b31 100644 --- a/VirtualGroupEx.Server/Middlewares/PostLoginMiddleware.cs +++ b/VirtualGroupEx.Server/Middlewares/PostLoginMiddleware.cs @@ -65,7 +65,7 @@ await signInManager.PasswordSignInAsync( if (httpContext.Request.Path == options.LogOutPath) { logger.LogInformation( - $"IP[{httpContext.Request.Host.Value}] User [{httpContext.User.Identity.Name}] logged out"); + $"User [{httpContext.User.Identity.Name}] logged out"); await signInManager.SignOutAsync(); httpContext.Response.Redirect("/");