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

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. 代码片段 - Golang 实现简单的 Web 服务器

    ------------------------------ 下面一段代码,实现了最简单的 Web 服务器: 编译环境: Linux Mint 18 Cinnamon 64-bit Golang 1. ...

  2. linux装完整版

    1.100G空间 计算机管理→磁盘管理→100G的逻辑分区(如果有三个主分区,linux就不能继续安装了) 2.iso工具写入硬盘镜像

  3. LeetCode13 Roman to Integer

    题意: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...

  4. js的2种继承方式详解

    js中继承可以分为两种:对象冒充和原型链方式 一.对象冒充包括三种:临时属性方式.call()及apply()方式1.临时属性方式 复制代码代码如下: function Person(name){   ...

  5. C# unix时间戳转换

    场景:由于业务需要和java 开发的xxx系统对接日志,xxx系统中用“1465195479100” 来表示时间,C# 里面需要转换做一下逻辑处理,见代码段. C#获取的unix时间戳是10位,原因是 ...

  6. org.apache.solr.common.util.ContentStream.java及其实现类

    org.apache.solr.common.util.ContentStream.java 主要是获取文件,URL,字节数组,字符串等的数据流.主要方法又InputStream getStream( ...

  7. Comparison method violates its general contract

    生产环境出现的错误排查,错误log如下 java.lang.IllegalArgumentException: Comparison method violates its general contr ...

  8. 【AsyncTask整理 1】 AsyncTask几点要注意的地方

    问题1:AsyncTask是多线程吗? 答:是. 问题2:AsyncTask与Handler相比,谁更轻量级? 答:通过看源码,发现AsyncTask实际上就是一个线程池,而网上的说法是AsyncTa ...

  9. (转)WIN7更改用户名访问共享文件夹

    原文地址: http://ryy8013.blog.163.com/blog/static/71729589201210610533778/ 一直以来,windows7客户端访问windows ser ...

  10. (转)Linux IO模式及 select、poll、epoll详解

    本文为转载,并作了部门调整.修改. [原文出处:https://segmentfault.com/a/1190000003063859] 同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么 ...