public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add( new HttpCookie(_webLocalizationConfiguration.CookieName, cultureName) { Expires = Clock.Now.AddYears(2) } ); if (AbpSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( AbpSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && AbpUrlHelper.IsLocalUrl(Request.Url, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect(Request.ApplicationPath)); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("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 (Request.IsAjaxRequest()) { return(Json(new MvcAjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //TODO: Go to app root }
/// <summary> /// This method is called by ASP.NET system when a request starts. /// </summary> protected virtual void Application_BeginRequest(object sender, EventArgs e) { //获取cookie语言环境值 var langCookie = Request.Cookies["Abp.Localization.CultureName"]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { //设置当前语言环境 Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); } else if (!Request.UserLanguages.IsNullOrEmpty()) { //获取客户端默认语言环境 var firstValidLanguage = Request .UserLanguages .FirstOrDefault(GlobalizationHelper.IsValidCultureCode); if (firstValidLanguage != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(firstValidLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(firstValidLanguage); } } }
/// <summary> /// This method is called by ASP.NET system when a request starts. /// </summary> protected virtual void Application_BeginRequest(object sender, EventArgs e) { var langCookie = Request.Cookies["Abp.Localization.CultureName"]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); } }
protected virtual string GetCultureFromHeader(HttpContext httpContext) { var culture = httpContext.Request.Headers[_webLocalizationConfiguration.CookieName]; if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
protected virtual string GetDefaultCulture() { var culture = _settingManager.GetSettingValue(LocalizationSettingNames.DefaultLanguage); if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
public override Task <ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext) { var defaultLanguage = _settingManager.GetSettingValue(LocalizationSettingNames.DefaultLanguage); if (defaultLanguage.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(defaultLanguage)) { return(Task.FromResult((ProviderCultureResult)null)); } var providerResultCulture = new ProviderCultureResult(defaultLanguage, defaultLanguage); return(Task.FromResult(providerResultCulture)); }
protected virtual string GetCultureFromQueryString(HttpContext httpContext) { // var culture = httpContext.Request.QueryString[_webLocalizationConfiguration.CookieName]; var culture = httpContext.Request["cultureName"]; if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("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), HttpOnly = true } ); if (AbpSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( AbpSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl)) { var escapedReturnUrl = Uri.EscapeDataString(returnUrl); var localPath = UrlHelper.LocalPathAndQuery(escapedReturnUrl, Request.Host.Host, Request.Host.Port); if (!string.IsNullOrWhiteSpace(localPath)) { var unescapedLocalPath = Uri.UnescapeDataString(localPath); if (Url.IsLocalUrl(unescapedLocalPath)) { return(LocalRedirect(unescapedLocalPath)); } } } return(LocalRedirect("/")); //TODO: Go to app root }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("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 (AbpSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( AbpSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl)) { var escapedReturnUrl = Uri.EscapeUriString(returnUrl); var localPath = UrlHelper.LocalPathAndQuery(escapedReturnUrl, Request.Url.Host, Request.Url.Port); if (!string.IsNullOrWhiteSpace(localPath)) { var unescapedLocalPath = Uri.UnescapeDataString(localPath); if (Url.IsLocalUrl(unescapedLocalPath)) { return(Redirect(unescapedLocalPath)); } } } return(Redirect(Request.ApplicationPath)); }
protected virtual void SetCurrentCulture() { var langCookie = Request.Cookies["Abp.Localization.CultureName"]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); } else if (!Request.UserLanguages.IsNullOrEmpty()) { var firstValidLanguage = Request?.UserLanguages?.FirstOrDefault(GlobalizationHelper.IsValidCultureCode); if (firstValidLanguage != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(firstValidLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(firstValidLanguage); } } }
/// <summary> /// 设置当前区域信息 /// </summary> protected virtual void SetCurrentCulture() { var globalizationSection = WebConfigurationManager.GetSection("globalization") as GlobalizationSection; if (globalizationSection != null && !globalizationSection.UICulture.IsNullOrEmpty() && !string.Equals(globalizationSection.UICulture, "auto", StringComparison.InvariantCultureIgnoreCase)) { return; } var langCookie = Request.Cookies[_webLocalizationConfiguration.CookieName]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); return; } var defaultLanguage = AbpBootstrapper.IocManager.Using <ISettingManager, string>(settingManager => settingManager.GetSettingValue(LocalizationSettingNames.DefaultLanguage)); if (!defaultLanguage.IsNullOrEmpty() && GlobalizationHelper.IsValidCultureCode(defaultLanguage)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(defaultLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(defaultLanguage); Response.SetCookie(new HttpCookie(_webLocalizationConfiguration.CookieName, defaultLanguage)); return; } if (!Request.UserLanguages.IsNullOrEmpty()) { var firstValidLanguage = Request?.UserLanguages?.FirstOrDefault(GlobalizationHelper.IsValidCultureCode); if (firstValidLanguage != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(firstValidLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(firstValidLanguage); Response.SetCookie(new HttpCookie(_webLocalizationConfiguration.CookieName, firstValidLanguage)); } } }
private string GetCultureFromUserSetting() { if (_CodeZeroSession.UserId == null) { return(null); } var culture = _settingManager.GetSettingValueForUser( LocalizationSettingNames.DefaultLanguage, _CodeZeroSession.TenantId, _CodeZeroSession.UserId.Value, fallbackToDefault: false ); if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new CodeZeroException("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), HttpOnly = true } ); if (CodeZeroSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( CodeZeroSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl) && CodeZeroUrlHelper.IsLocalUrl(Request, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //TODO: Go to app root }
public ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add(new HttpCookie("Abp.Localization.CultureName", cultureName) { Expires = DateTime.Now.AddYears(2) }); if (Request.IsAjaxRequest()) { return(Json(new AbpMvcAjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Append("Abp.Localization.CultureName", cultureName, new CookieOptions { Expires = Clock.Now.AddYears(2) }); //if (Request.IsAjaxRequest()) //{ // return Json(new MvcAjaxResponse(), JsonRequestBehavior.AllowGet); //} if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //return Redirect(Request.ApplicationPath); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new Exception("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add( new HttpCookie(_webLocalizationConfiguration.CookieName, cultureName) { Expires = DateTime.Now.AddYears(2), Path = Request.ApplicationPath } ); ValidatorOptions.LanguageManager.Enabled = true; ValidatorOptions.LanguageManager.Culture = new System.Globalization.CultureInfo(cultureName); if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null)// && AbpUrlHelper.IsLocalUrl(Request.Url, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect(Request.ApplicationPath)); }