abpframework / abpframework/abp
Angular: CookieLanguageProvider creates incorrect cookie path when app is hosted in a virtual directory
@sumeyyeKurtulus is already working on this.
Since Jul 23, 2026.
- Dominant language
- C#
- Stars
- 14.4k
- Forks
- 3.7k
- Avg merge
- 15h 32m
- Merged PRs (30d)
- 106
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Currently, CookieLanguageProvider in @abp/ng.core writes the localization cookie without explicitly setting a Path attribute:
document.cookie = ${cookieLanguageKey}=${cookieValue};
When the Angular application is hosted under a virtual directory (for example /web), browsers default the cookie path to the current request path, resulting in:
Path=/web
instead of:
Path=/
As a result, the localization cookie is not sent on requests to endpoints outside /web (such as /api), preventing the backend from determining the user's selected culture from the cookie.
This issue only occurs when the Angular application is hosted in a sub-path. Applications hosted at the site root (/) are unaffected because the browser defaults the cookie path to /.
Describe the solution you'd like
I suggest either:
- Explicitly setting the cookie path to / when writing the localization cookie, for example:
document.cookie =${cookieLanguageKey}=${cookieValue}; Path=/;
or
Exposing the cookie path as a configurable option in provideAbpCore() or CookieLanguageProvider, allowing applications hosted in virtual directories to configure the desired cookie path.
For most deployments, using Path=/ as the default would make the localization cookie available across the entire application and avoid unexpected behavior when the Angular application is hosted under a virtual directory.
Additional context
Our application is hosted under /web, while backend endpoints are hosted outside that path (e.g. /api). Because the localization cookie is created with Path=/web, the browser does not include it in requests to the backend, causing the selected UI culture not to be applied for server-side requests.
Changing the cookie to use Path=/ resolves the issue.
EDIT:
After some tests, i realised that the problem really occurs because my AuthServer is pointing at path=/ while my Angular is pointing at path=/web.
For people with same problem, just make a workaround to override the current CookieLanguageProvider:
import { Injector, inject, provideAppInitializer, PLATFORM_ID } from '@angular/core';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { SessionStateService } from '@abp/ng.core';
export function setLanguageToCookie() {
const injector = inject(Injector);
const platformId = injector.get(PLATFORM_ID);
if (!isPlatformBrowser(platformId)) return;
const sessionState = injector.get(SessionStateService);
const document = injector.get(DOCUMENT);
const cookieLanguageKey = '.AspNetCore.Culture';
sessionState.getLanguage$().subscribe(language => {
const cookieValue = encodeURIComponent(`c=${language}|uic=${language}`);
document.cookie = `${cookieLanguageKey}=${cookieValue}; path=/`;
});
}
export const LanguageCookieOverrideProvider = provideAppInitializer(() => {
setLanguageToCookie();
});
Then call it after provideAbpCore():
provideAbpCore(
withOptions({
environment,
registerLocaleFn: registerLocale(),
}),
),
LanguageCookieOverrideProvider,
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.