• Not Answered

Rename Sitecore Language Cookie (Remove Special Character #)

Is it possible to rename the sitecore language cookie? I believe it follows the format [websitename]@lang. I tried to rename it via the web.config but it just created both cookies and sitecore still uses the original one.

1 Reply

  • I am not sure if you can do it but you can see below code which Sitecore is using for setting up the language cookie. In Sitecore.Kernel.dll

     

    public static void SetLanguage(Language language, bool persistent)
    {
    Assert.ArgumentNotNull((object) language, nameof (language));
    Context.Items["sc_Language"] = (object) language;
    if (!persistent)
    return;
    SiteContext site = Context.Site;
    if (site == null)
    return;
    string cookieKey = site.GetCookieKey("lang");
    if (!(WebUtil.GetCookieValue(cookieKey) != language.Name))
    return;
    WebUtil.SetCookieValue(cookieKey, language.Name);
    }

     

    And there is a function in SiteContext extension that is making that update -  

     

    /// <summary>Gets the cookie key.</summary>
    /// <param name="siteName">Name of the site.</param>
    /// <param name="name">The name.</param>
    /// <returns>The cookie key.</returns>
    internal static string GetCookieKey(string siteName, string name)
    {
    Sitecore.Diagnostics.Assert.ArgumentNotNull((object) siteName, nameof (siteName));
    Sitecore.Diagnostics.Assert.ArgumentNotNull((object) name, nameof (name));
    return (siteName + "#" + name).ToLowerInvariant();
    }

     

    If you can update the SetLanguage function I think you can achieve the same and put the cookie name whatever you want.