public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new StudioXException("Unknown language: " + cultureName + ". It must be a valid culture!"); } var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName)); Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions { Expires = Clock.Now.AddYears(2) } ); if (StudioXSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( StudioXSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl) && StudioXUrlHelper.IsLocalUrl(Request, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //TODO: Go to app root }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new StudioXException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add( new HttpCookie(webLocalizationConfiguration.CookieName, cultureName) { Expires = Clock.Now.AddYears(2), Path = Request.ApplicationPath } ); if (StudioXSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( StudioXSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && StudioXUrlHelper.IsLocalUrl(Request.Url, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect(Request.ApplicationPath)); }