From 4e0037d8fe3ee880024d99bdee7c64cd31572322 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 17 Jan 2025 13:20:14 +0800 Subject: [PATCH] Set `.AspNetCore.Culture` cookie `path` to `/`. --- .../wwwroot/libs/abp/js/abp.js | 3 +++ .../Themes/Basic/LanguageSwitch.razor | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js b/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js index 51ff0151b6..ef9d6d6103 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js @@ -36,6 +36,9 @@ var abp = abp || {}; if (path) { cookieValue = cookieValue + "; path=" + path; + } else { + + cookieValue = cookieValue + "; path=/"; } if (secure) { diff --git a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LanguageSwitch.razor b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LanguageSwitch.razor index 01cd632615..7814000136 100644 --- a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LanguageSwitch.razor +++ b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LanguageSwitch.razor @@ -1,8 +1,10 @@ @using Volo.Abp.Localization @using System.Globalization @using System.Collections.Immutable +@using Volo.Abp.AspNetCore.Components.Web @inject ILanguageProvider LanguageProvider @inject IJSRuntime JsRuntime +@inject ICookieService CookieService @if (_otherLanguages != null && _otherLanguages.Any()) { @@ -57,20 +59,23 @@ { await JsRuntime.InvokeVoidAsync( "localStorage.setItem", - "Abp.SelectedLanguage", + "Abp.SelectedLanguage", language.UiCultureName ); await JsRuntime.InvokeVoidAsync( "localStorage.setItem", - "Abp.IsRtl", + "Abp.IsRtl", CultureInfo.GetCultureInfo(language.UiCultureName).TextInfo.IsRightToLeft ); - await JsRuntime.InvokeVoidAsync( - "abp.utils.setCookieValue", + await CookieService.SetAsync( ".AspNetCore.Culture", - $"c={language.CultureName}|uic={language.UiCultureName}" + $"c={language.CultureName}|uic={language.UiCultureName}", + new CookieOptions + { + Path = "/" + } ); await JsRuntime.InvokeVoidAsync("location.reload");