From 2435e149b1fd8cf484916dbdedc7d765789e8b02 Mon Sep 17 00:00:00 2001 From: Peter Donker Date: Fri, 30 Oct 2020 10:28:40 +0100 Subject: [PATCH] Simplify cookie setting to avoid duplicate language cookies being set --- .../Services/Localization/Localization.cs | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/DNN Platform/Library/Services/Localization/Localization.cs b/DNN Platform/Library/Services/Localization/Localization.cs index b162fedc5ce..2a589a05ba9 100644 --- a/DNN Platform/Library/Services/Localization/Localization.cs +++ b/DNN Platform/Library/Services/Localization/Localization.cs @@ -1569,26 +1569,11 @@ public static void SetLanguage(string value) } // save the page culture as a cookie - HttpCookie cookie = response.Cookies.Get("language"); - if (cookie == null) + response.Cookies.Remove("language"); + if (!string.IsNullOrEmpty(value)) { - if (!string.IsNullOrEmpty(value)) - { - cookie = new HttpCookie("language", value) { Path = !string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/" }; - response.Cookies.Add(cookie); - } - } - else - { - cookie.Value = value; - if (!string.IsNullOrEmpty(value)) - { - response.Cookies.Set(cookie); - } - else - { - response.Cookies.Remove("language"); - } + var cookie = new HttpCookie("language", value) { Path = !string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/" }; + response.Cookies.Add(cookie); } } catch