- ABP Framework version: v5.1.2
- UI type: Angular and MVC
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:"
- Log in
- When on the Home page or any other page, try to switch the language -> some elements are updated in the target language but most don't
As you can see in the screen shot, there are 2 cookies .AspNetCore.Culture : one with path /CentralTools/Dev/masterdata and another with path /
After login, both of them have the same value, for example French.
When I change the language to English, only the one with the /CentralTools/Dev/masterdata path gets updated.
If I delete the other one (with path /) then everything works well ; I can change language any time, it is ok. But obviously we are not going to ask users to delete manually the cookie each time they log in...
What would you suggest to address this issue ?
Thanks,
Thomas
PS : This issue doe not happen locally or if the website is deployed at the root with IIS.
14 Answer(s)
-
0
Can you try it in incognito mode? Also, can you share your domain names?
The culture (with
/
path) can be already set by other domain before you navigate to sub-domain. -
0
I have tried in incognito mode, no luck, same behavior.
You woud not have access to our integration server for security reasons ; I have tried from home, it does not work.
The culture (with / path) can be already set by other domain before you navigate to sub-domain.
This is probably true. The cookie with path '/' is set up at login. The cookie with the path /Centraltools/masterdata is set up at login and updated when I use the switch language feature.
Still I have no clue on how to advance from here. I was thinking maybe, I have to override the switch language cookie creation mechanism or on the contrary block the creation of the cookie with root '/'.
Any suggestion is welcome.
Thanks
Thomas
-
0
thank you I assigned your issue to @gterdem. he'll help you on that.
-
0
We can do a Teams or TeamViewer session if that helps. Just send me an email.
Thanks
-
0
this doesn't seem to be a framework or ABP commercial template issue. it's related to IIS that's why better to ask on the IIS support website. On the other hand, you can try to change the cookie path in your module class.
services.ConfigureApplicationCookie(options => { options.Cookie.Path = "/"; });
-
0
Hello Albert,
Thank you for the answer. I'll test it asap.
Thomas
-
0
ok. you can inform us about the recent status.
-
0
Hello Albert,
I am sorry but I could not test as we have a blocking issue with the build since thursday . I will test what you have suggested as soon as I can.
Thomas
-
0
then I'm closing the issue. you can always reopen
-
0
Hello Albert,
So I went digging for my whole day yesterday into ABP and ABP commercial source code and I have found the issue :
The script that is responsible for setting the cookie is missing something :
function setLanguageToCookie(injector) { return () => { const sessionState = injector.get(SessionStateService); const document = injector.get(DOCUMENT); const cookieLanguageKey = injector.get(COOKIE_LANGUAGE_KEY); sessionState.getLanguage$().subscribe(language => { const cookieValue = encodeURIComponent(
c=${language}|uic=${language}
); document.cookie =${cookieLanguageKey}=${cookieValue}
; }); };If the path of the cookie is not specified then it is assigned to the path of the current page, which causes the problem in my case ; thus the fix (tested) is to change the line :
document.cookie =
${cookieLanguageKey}=${cookieValue}
;to
document.cookie =
${cookieLanguageKey}=${cookieValue};path=/
;I did change manually the generated script (main.js) on the server to test but I do not know where I should do this change for a clean fix.
Could you tell me in which file I should do the change before compiling ?
Thanks
Thomas
-
0
Hello Albert,
So I went digging for my whole day yesterday into ABP and ABP commercial source code and I have found the issue :
The script that is responsible for setting the cookie is missing something :
function setLanguageToCookie(injector) { return () => { const sessionState = injector.get(SessionStateService); const document = injector.get(DOCUMENT); const cookieLanguageKey = injector.get(COOKIE_LANGUAGE_KEY); sessionState.getLanguage$().subscribe(language => { const cookieValue = encodeURIComponent(
c=${language}|uic=${language}
); document.cookie =${cookieLanguageKey}=${cookieValue}
; }); };If the path of the cookie is not specified then it is assigned to the path of the current page, which causes the problem in my case ; thus the fix (tested) is to change the line :
document.cookie =
${cookieLanguageKey}=${cookieValue}
;to
document.cookie =
${cookieLanguageKey}=${cookieValue};path=/
;I did change manually the generated script (main.js) on the server to test but I do not know where I should do this change for a clean fix.
Could you tell me in which file I should do the change before compiling ?
Thanks
Thomas
is this from the Angular project?
-
0
-
0
Hello,
You can change the culture cookie with the code below
//app.component.ts import { COOKIE_LANGUAGE_KEY, SessionStateService } from '@abp/ng.core'; import { Component, Inject, OnInit } from '@angular/core'; import { DOCUMENT } from '@angular/common'; @Component({ selector: 'app-root', template: ` <abp-loader-bar></abp-loader-bar> <abp-dynamic-layout></abp-dynamic-layout> `, }) export class AppComponent implements OnInit { constructor( private sessionState: SessionStateService, @Inject(DOCUMENT) private document: Document, @Inject(COOKIE_LANGUAGE_KEY) private cookieLanguageKey: string ) {} ngOnInit(): void { this.updateCookieOnLanguageChange(); } updateCookieOnLanguageChange() { this.sessionState.getLanguage$().subscribe(language => { // remove the old one first this.document.cookie = `${this.cookieLanguageKey}=; expires=Thu, 01 Jan 1970 00:00:01 GMT;`; const cookieValue = encodeURIComponent(`c=${language}|uic=${language}`); this.document.cookie = `${this.cookieLanguageKey}=${cookieValue};path=/`; }); } }
-
0
Hello Muhammed,
I thank you for your message. I have tested your suggested changes and it is working.
Should this change incorporated in ABP next version as well ? I do not quite understand why this language cookie is pretty much the only cookie missing path=/ .
Thomas