Ends in:
2 DAYS
12 HRS
7 MIN
40 SEC
Ends in:
2 D
12 H
7 M
40 S
Open Closed

Language switch feature not working on server hosted by IIS #3225


User avatar
0
thomas.blotiere@abraxas.ch created
  • 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)
  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    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.

  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    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

  • User Avatar
    0
    alper created
    Support Team Director

    thank you I assigned your issue to @gterdem. he'll help you on that.

  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    We can do a Teams or TeamViewer session if that helps. Just send me an email.

    Thanks

  • User Avatar
    0
    alper created
    Support Team Director

    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 = "/";
      });
    
  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    Hello Albert,

    Thank you for the answer. I'll test it asap.

    Thomas

  • User Avatar
    0
    alper created
    Support Team Director

    ok. you can inform us about the recent status.

  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    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

  • User Avatar
    0
    alper created
    Support Team Director

    then I'm closing the issue. you can always reopen

  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    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

  • User Avatar
    0
    alper created
    Support Team Director

    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?

  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    I would think so, cf screenshot

  • User Avatar
    0
    muhammedaltug created

    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=/`;
        });
      }
    }
    
  • User Avatar
    0
    thomas.blotiere@abraxas.ch created

    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

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35