Search code examples
c#internationalizationumbracomultilingual

What can I use on my multilingual website to store data between language switches?


I am currently making a multilingual website in Umbraco (C#/Razor MVC CMS).

I have 3 languages, all have their own domain name, but all point to the same Umbraco installation. For example:

multilingualwebsite-fr.com
multilingualwebsite-en.com
multilingualwebsite-de.com

When the user picks a different language from the dropdown the site redirects to the domain associated with that language which tells the CMS to switch the language.

I would like to transfer a small amount of data between these domains regarding the user, i.e if they have accepted a pop-up or closed the cookie bar.

I have looked at using cookies and sessions but it has become apparent that these only work on the same domain they are created on so cannot transfer data between each language site. So I cannot read the cookie/session data once the language has been switched.

I have added parameters to the url when the language is switched so the URL looks something like

multilingualwebsite-fr.com?nopopup=true&cookieaccepted=true

but I find these parameters untidy and it is likely that I am going to need to pass more information in the future and this will just get longer.

Are there any better ways of transferring data from one domain to another that I have not thought of?

In hindsite having multilingualwebsite.com/fr/ style domains would have excluded this issue but it isn't want the client wants for their website.


Solution

  • Modern browsers are very restrictive when it comes to cross-domain communication. You are better off doing something on the server-side.

    If all the domains point to the same actual application, then you can just store something in memory when you know the user will be switching languages.

    Something like this:

    1. User clicks new language.
    2. Send AJAX request to current domain to tell the server the user is changing languages.
    3. Server saves user information in memory.
    4. Browser redirects to new language domain.
    5. Server authenticates user at new language domain.
    6. Server checks for stored user information, and if found, uses it.

    If each language domain is a different application, then the server can make an HTTP call to the new language domain to tell it that the user is coming.