Fix #4936: set the allow cookie value when refresh state.

This commit is contained in:
Ben 2025-03-01 14:16:42 +08:00
parent b3716da5ac
commit 8f4a20fd46

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);