公司业务需要在国外开展了, 因此以前的系统要做多国语言了, 从网上搜集了好多资料, 最后选择了一个比较简单的方案

1.  打开vs2005, 新建网站,

  首先在配置文件中添加配置:

  <system.web>

    <globalization culture="auto" uiCulture="auto"/>

  </system.web>

  添加asp.net文件夹App_GlobalResources, 添加“资源文件”, 如下图

  

2. 复制Resource.resx, 粘贴到App_GlobalResources文件夹下, 更改名称为Resource.en-us.resx,内容更改如下:

  

3. asp:Label调用

  <asp:Label ID="Label1" runat="server" Text="<%$Resources:Resource,msg1%>"></asp:Label>

4. asp:Button调用

  <asp:Button ID="Button1" runat="server" Text="<%$ Resources:Resource,msg1 %>" OnClientClick="test();" />

5. js调用

  alert("<%=Resources.Resource.msg1 %>");

6 后台调用

  <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

  Label2.Text = Convert.ToString(GetGlobalResourceObject("Resource", "msg1"));

7. 图片资源

  <asp:Image ID="Image1" runat="server" />

  然后在Page_Load中Image1.ImageUrl = "~/Image.aspx?culture=" + Convert.ToString(Session["culture"]);

  

protected override void InitializeCulture()
{
base.InitializeCulture();
if (null != Session["culture"])
{
string c = Convert.ToString(Session["culture"]);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(c);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(c); }
} protected void Page_Load(object sender, EventArgs e)
{
string c = Request["culture"];
System.Drawing.Bitmap img = (System.Drawing.Bitmap)GetGlobalResourceObject("Resource","test"); System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); Response.ClearContent();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(ms.ToArray()); img.Dispose();
ms.Dispose();
ms.Flush();
}

8 手动设置语言

  

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="zh-cn">中文</asp:ListItem>
<asp:ListItem Value="en-us">english</asp:ListItem>
</asp:DropDownList>
protected override void InitializeCulture()
{
base.InitializeCulture();
if (null != Session["culture"])
{
string c = Convert.ToString(Session["culture"]);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(c);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(c);
}
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string c = DropDownList1.SelectedValue;
if (!string.IsNullOrEmpty(c))
{
Session["culture"] = c;
this.Response.Redirect("~/Default.aspx", true);
}
}

asp.net2.0 国际化的更多相关文章

  1. 【IHttpHandler】在ASP.Net2.0中使用UrlRewritingNet实现链接重写

    很多时候我们需要链接转向(Url Rewriting),例如二级域名转向.文章访问链接等场合. 让我们看两个例子: 1 你现在看到的当前作者的博客园的域名: http://jx270.cnblogs. ...

  2. asp.net2.0安全性(2)--用户个性化设置(1)--转载来自车老师

    在Membership表中可以存储一些用户的基本信息,但有的时候,我们需要记录的用户信息远远不止Membership表中提供的这些,如QQ.MSN.家庭住址.联系电话等等.那如何把这些用户信息记录到数 ...

  3. asp.net2.0安全性(2)--用户个性化设置(2)--转载来自车老师

    上一篇我们用Profile.age等方式可以读取用户的年龄和其它的信息,但有的时候我们要查询显示所有用户的信息,但asp.net没有提供查询所有用户信息的功能,我们只能对现有的用户逐一查询其Profi ...

  4. asp.net2.0安全性(3)--验证与授权--转载来自车老师

    "验证"与"授权"是对网页资源安全管理的两道门. 验证(Authentication):检查用户是否是合法的用户.就像是网站大门口的保卫,服责验证使用的用户名和 ...

  5. asp.net2.0安全性(1)--用户角色篇(类)--转载来自车老师

    Membership.MembershipUser和Roles类 用户与角色管理在asp.net2.0中是通过Membership和Roles两个类来实现的. Membership:用户成员账号管理, ...

  6. asp.net2.0安全性(1)--用户角色篇(起篇)--转载来自车老师

    安全管理的解决方案在.net1.1中几乎为一片空白,对于应用程序的验证与授权大部分的工作是开发人员自己编写代码,或者是借助企业库等工具来实现,此可谓.net1.1中的一大缺憾.在.net2.0中微软为 ...

  7. Asp.Net2.0下C#环境 Login控件实现用户登录

    原文:Asp.Net2.0下C#环境 Login控件实现用户登录 一.前台显示效果 二.前台代码             <asp:Login ID="Login1" run ...

  8. ASP.NET2.0组件控件开发视频 初体验

    原文:ASP.NET2.0组件控件开发视频 初体验 ASP.NET2.0组件控件开发视频 初体验 录了视频,质量不是很好,大家体验下.我会重新录制的 如果不清楚,可以看看http://v.youku. ...

  9. ASP.NET2.0自定义控件组件开发 第六章 深入讲解控件的属性

    原文:ASP.NET2.0自定义控件组件开发 第六章 深入讲解控件的属性 深入讲解控件的属性持久化(一) 系列文章链接: ASP.NET自定义控件组件开发 第一章 待续 ASP.NET自定义控件组件开 ...

随机推荐

  1. Aggressive cows 二分不仅仅是查找

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7083   Accepted: 3522 Description Farme ...

  2. Python操作MySQL之SQLAlchemy

      SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据API执行SQL并获取执行结 ...

  3. 【Android 界面效果12】EditText中的多行输入问题

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 我们在使用EditText进行多行输入的时候,通常的写法如下: <EditText android ...

  4. OpenGL ES应用开发实践指南:iOS卷

    <OpenGL ES应用开发实践指南:iOS卷> 基本信息 原书名:Learning OpenGL ES for iOS:A Hands-On Guide to Modern 3D Gra ...

  5. Gulp 自动化的项目构建工具

    在很多场合都会听到前端工和 node 程师推荐 Grunt 来实现项目的自动化,自动化可以自动完成 javascript/coffee/sass/less 等文件的的测试.检查.合并.压缩.格式化.部 ...

  6. java多线程之Future和FutureTask

    Executor框架使用Runnable 作为其基本的任务表示形式.Runnable是一种有局限性的抽象,然后可以写入日志,或者共享的数据结构,但是他不能返回一个值. 许多任务实际上都是存在延迟计算的 ...

  7. 自定义TabBarController报错 - Unbalanced calls to begin/end appearance transitions for <>

    自定义了TabBarController 之后必须实现以下方法才能避免报错 -(void)viewWillAppear:(BOOL)animated { [self.selectedViewContr ...

  8. Python之类型转换

    函数 描述 int(x [,base]) 将x转换为一个整数 long(x [,base] ) 将x转换为一个长整数 float(x) 将x转换到一个浮点数 complex(real [,imag]) ...

  9. iPhone开发 Swift - NSNotification 通知

    Swift创建Notification通知 创建一个SingleView Application 打开AppDelegate.swift,在方法 application(application:UIA ...

  10. Meta也很强

    <!--http-equiv 必要属性--> <meta http-equiv="Content-Type" content="text/html; c ...