From ffca1d24860b2777c22c0e56e0df353ac9af9574 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Tue, 7 Feb 2023 16:26:23 -0500 Subject: [PATCH] refactor visitor cookie name into a shared constant --- Oqtane.Client/Modules/Admin/Logs/Index.razor | 2 +- Oqtane.Server/Controllers/SettingController.cs | 2 +- Oqtane.Server/Controllers/VisitorController.cs | 2 +- Oqtane.Server/Pages/_Host.cshtml.cs | 2 +- Oqtane.Shared/Shared/Constants.cs | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Logs/Index.razor b/Oqtane.Client/Modules/Admin/Logs/Index.razor index ed0c586c..79f2a7b9 100644 --- a/Oqtane.Client/Modules/Admin/Logs/Index.razor +++ b/Oqtane.Client/Modules/Admin/Logs/Index.razor @@ -237,7 +237,7 @@ else protected override void OnAfterRender(bool firstRender) { - if (!firstRender) + if (firstRender) { // external link to log item will display Details component if (PageState.QueryString.ContainsKey("id") && int.TryParse(PageState.QueryString["id"], out int id)) diff --git a/Oqtane.Server/Controllers/SettingController.cs b/Oqtane.Server/Controllers/SettingController.cs index 3f38259e..d4da807a 100644 --- a/Oqtane.Server/Controllers/SettingController.cs +++ b/Oqtane.Server/Controllers/SettingController.cs @@ -46,7 +46,7 @@ namespace Oqtane.Controllers _identityCache = identityCache; _logger = logger; _alias = tenantManager.GetAlias(); - _visitorCookie = "APP_VISITOR_" + _alias.SiteId.ToString(); + _visitorCookie = Constants.VisitorCookiePrefix + _alias.SiteId.ToString(); } // GET: api/ diff --git a/Oqtane.Server/Controllers/VisitorController.cs b/Oqtane.Server/Controllers/VisitorController.cs index dfb9a63c..c4a8de73 100644 --- a/Oqtane.Server/Controllers/VisitorController.cs +++ b/Oqtane.Server/Controllers/VisitorController.cs @@ -50,7 +50,7 @@ namespace Oqtane.Controllers bool authorized = User.IsInRole(RoleNames.Admin); if (!authorized) { - var visitorCookie = "APP_VISITOR_" + _alias.SiteId.ToString(); + var visitorCookie = Constants.VisitorCookiePrefix + _alias.SiteId.ToString(); if (int.TryParse(Request.Cookies[visitorCookie], out int visitorId)) { authorized = (visitorId == id); diff --git a/Oqtane.Server/Pages/_Host.cshtml.cs b/Oqtane.Server/Pages/_Host.cshtml.cs index 135493fc..bf49849b 100644 --- a/Oqtane.Server/Pages/_Host.cshtml.cs +++ b/Oqtane.Server/Pages/_Host.cshtml.cs @@ -284,7 +284,7 @@ namespace Oqtane.Pages // check if cookie already exists Visitor visitor = null; bool addcookie = false; - var VisitorCookie = "APP_VISITOR_" + SiteId.ToString(); + var VisitorCookie = Constants.VisitorCookiePrefix + SiteId.ToString(); if (!int.TryParse(Request.Cookies[VisitorCookie], out VisitorId)) { // if enabled use IP Address correlation diff --git a/Oqtane.Shared/Shared/Constants.cs b/Oqtane.Shared/Shared/Constants.cs index 3ec91104..15e9af81 100644 --- a/Oqtane.Shared/Shared/Constants.cs +++ b/Oqtane.Shared/Shared/Constants.cs @@ -73,6 +73,7 @@ namespace Oqtane.Shared public static readonly string HttpContextSiteSettingsKey = "SiteSettings"; public static readonly string MauiUserAgent = "MAUI"; + public static readonly string VisitorCookiePrefix = "APP_VISITOR_"; // Obsolete constants