日期:2014-05-18 浏览次数:20497 次
/// <summary> /// 语言文化区域性控制 /// </summary> public abstract class Culture : System.Web.UI.Page { /// <summary> /// 重写Page基类的InitializeCulture方法。 /// 为页的当前线程设置 System.Web.UI.Page.Culture 和 System.Web.UI.Page.UICulture。 /// </summary> protected override void InitializeCulture() { if (!string.IsNullOrEmpty(CultureCache)) { SetCulture(CultureCache); } else { SetCulture(DefaltCulture); } } /// <summary> /// 设置指定文化 /// </summary> /// <param name="culture">有效的区域性名称</param> public static void SetCulture(string culture) { try { Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); } catch { culture = DefaltCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); } CultureCache = culture; UICultureCache = culture; } /// <summary> /// 获取当前应用程序默认文化 /// </summary> public static string DefaltCulture { get { string culture = ConfigurationManager.AppSettings["Culture"].ToString(); if (string.IsNullOrEmpty(culture) || culture == "auto") { return Thread.CurrentThread.CurrentCulture.ToString(); } return culture; } } /// <summary> /// 存储当前Culture Session /// </summary> public static string CultureCache { get { try { return HttpContext.Current.Request.Cookies[ConfigurationManager.AppSettings["CultureCache"].ToString()].Value; } catch { return string.Empty; } } set { HttpContext.Current.Response.Cookies[ConfigurationManager.AppSettings["CultureCache"].ToString()].Value = value; } } /// <summary> /// 存储当前UICulture Session /// </summary> public static string UICultureCache { get { try { return HttpContext.Current.Request.Cookies[ConfigurationManager.AppSettings["UICultureCache"].ToString()].Value; } catch { return string.Empty; } }