Merge pull request #5130 from zyhfish/task/fix-4936

Fix #4936: set the allow cookie value when refresh state.
This commit is contained in:
Shaun Walker 2025-03-03 07:57:42 -05:00 committed by GitHub
commit 9e5922e121
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -120,6 +120,9 @@
cookieString = _canTrack ? await CookieConsentService.CreateConsentCookieAsync() : await CookieConsentService.WithdrawConsentCookieAsync(); cookieString = _canTrack ? await CookieConsentService.CreateConsentCookieAsync() : await CookieConsentService.WithdrawConsentCookieAsync();
} }
//update the page state
PageState.AllowCookies = _canTrack;
if (!string.IsNullOrEmpty(cookieString)) if (!string.IsNullOrEmpty(cookieString))
{ {
var interop = new Interop(JSRuntime); var interop = new Interop(JSRuntime);

View File

@ -14,6 +14,7 @@
@inject IUrlMappingService UrlMappingService @inject IUrlMappingService UrlMappingService
@inject ILogService LogService @inject ILogService LogService
@inject ISettingService SettingService @inject ISettingService SettingService
@inject ICookieConsentService CookieConsentService
@inject IJSRuntime JSRuntime @inject IJSRuntime JSRuntime
@implements IHandleAfterRender @implements IHandleAfterRender
@implements IDisposable @implements IDisposable
@ -293,6 +294,14 @@
// load additional metadata for modules // load additional metadata for modules
(page, modules) = ProcessModules(site, page, modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType, SiteState.Alias); (page, modules) = ProcessModules(site, page, modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType, SiteState.Alias);
//cookie consent
var _allowCookies = PageState?.AllowCookies;
if(!_allowCookies.HasValue)
{
var cookieConsentSettings = SettingService.GetSetting(site.Settings, "CookieConsent", string.Empty);
_allowCookies = string.IsNullOrEmpty(cookieConsentSettings) || await CookieConsentService.CanTrackAsync(cookieConsentSettings == "optout");
}
// populate page state (which acts as a client-side cache for subsequent requests) // populate page state (which acts as a client-side cache for subsequent requests)
_pagestate = new PageState _pagestate = new PageState
{ {
@ -316,7 +325,8 @@
ReturnUrl = returnurl, ReturnUrl = returnurl,
IsInternalNavigation = _isInternalNavigation, IsInternalNavigation = _isInternalNavigation,
RenderId = Guid.NewGuid(), RenderId = Guid.NewGuid(),
Refresh = false Refresh = false,
AllowCookies = _allowCookies.GetValueOrDefault(true)
}; };
OnStateChange?.Invoke(_pagestate); OnStateChange?.Invoke(_pagestate);