public static bool CheckLanguageCode() { var cookiesClientLangCode = HttpContext.Current.Request.Cookies.Get(CookiesKey.LangCode); if (cookiesClientLangCode != null) { if (LangCode.GetList().Any(x => x == cookiesClientLangCode.Value)) { return(true); } else { return(false); } } else { return(false); } }
public ActionResult SetLanguage(string code) { var returnUrl = HttpContext.Request.UrlReferrer.ToString() ?? "/"; if (LangCode.GetList().Any(x => x == code)) { var cookieLang = Request.Cookies[CookiesKey.LangCode]; if (cookieLang == null) { //create HttpCookie newLangCookie = new HttpCookie(CookiesKey.LangCode) { Value = code, Expires = DateTime.Now.AddDays(30) }; HttpContext.Response.Cookies.Add(newLangCookie); } else { //Update language var myCookie = new HttpCookie(CookiesKey.LangCode) { Expires = DateTime.Now.AddDays(-1d) }; Response.Cookies.Add(myCookie); var newLangCokie = new HttpCookie(CookiesKey.LangCode) { Value = code, Expires = DateTime.Now.AddDays(30) }; HttpContext.Response.Cookies.Add(newLangCokie); } } return(Redirect(returnUrl)); }
public static bool CheckLanguageCode() { var cookiesClientLangCode = HttpContext.Current.Request.Cookies.Get(CookiesKey.LangCode); return(cookiesClientLangCode != null && LangCode.GetList().Any(x => x == cookiesClientLangCode.Value)); }