⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform1.aspx.cs

📁 这是用c#作的一个网站的国际化
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Threading;
using System.Resources;
using System.Globalization;
using System.Diagnostics;
using System.Reflection;
namespace WebApplication1
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtLoginName;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		private void Page_Load(object sender, System.EventArgs e)
		{
			Label1.Text = Resource("LoginName");
			Label2.Text = Resource("Password");
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
        
		/**//// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region Resource
		public string Resource(string key)
		{
			string resourceValue = null;

			CultureInfo ci     = CultureInfo.CurrentCulture;
			ResourceManager rm = new ResourceManager("WebApplication1.strings", Assembly.GetExecutingAssembly());  
			resourceValue = rm.GetString(key,ci);
			return resourceValue;
		}
		#endregion

		private void Button2_Click(object sender, System.EventArgs e)
		{
			this.UpdateCultureCookie(ConfigurationSettings.AppSettings["ENCulture"].ToString());
			System.Web.UI.Page currentPage= (System.Web.UI.Page)this;
			Response.Redirect(currentPage.Request.Url.ToString());
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			this.UpdateCultureCookie(ConfigurationSettings.AppSettings["CNCulture"].ToString());
			System.Web.UI.Page currentPage= (System.Web.UI.Page)this;
			Response.Redirect(currentPage.Request.Url.ToString());
		}
		private void UpdateCultureCookie(string culture)
		{
			if(Request.Cookies["CultureResource"] != null)
			{
				Response.Cookies["CultureResource"].Value = culture;
				Response.Cookies["CultureResource"].Expires = System.DateTime.Now.AddDays(30);
			}
			else
			{
				HttpCookie cultureCookie = new HttpCookie("CultureResource");
				cultureCookie.Value = culture;
				cultureCookie.Expires = System.DateTime.Now.AddDays(30);
				Response.Cookies.Add(cultureCookie);
			}
		}   
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -