当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > WEB页面多语言支持解决方案

ASP.NET
安装IE补丁后ASP.NET将无法运行
在ASP.Net中应用Javascript
用ASP.NET 1.1 新特征防止Script攻击
ASP.NET中在线用户统计的简单实现及讨论
ASP.NET中将数据输出到Excel
在ASP.NET中从SQL Server检索图片
ASP.NET系统用户权限设计与实现
利用ASP.NET技术动态生成HTML页面
大数量查询分页显示 微软的解决办法
ASP.NET WEB页面多语言支持解决方案
ASP.NET 2.0里轻松获取数据库连接统计数据
ASP.NET通过DSO访问分析服务器的权限问题
ASP实现禁止从外部提交数据
Asp.Net 使用 GDI+ 绘制3D饼图入门篇源码
在ASP.NET中点击一个按钮后让它变灰的简单方法
利用JS在asp.net中实现左导航页的隐藏
asp.net中一次更新DATAGRID中所有记录
用Asp.net屏蔽F5、Ctrl+N、Alt+F4
asp.net中用C#实现站点计数器用户控件
认识ASP.NET配置文件Web.config

ASP.NET 中的 WEB页面多语言支持解决方案


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 60 ::
收藏到网摘: n/a

首先建立语言档,在项目中加入.resx文件
例如:
message.zh-cn.resx'简体中文
message.zh-tw.resx'繁体中文
message.en'英文
..............
=========================================
然后利用Name--Value键值对填入你要在页面上显示的语言
如:
namevalue
message.zh-cn.resx中:
res_loginbname登陆名:
message.zh-tw.resx中:
res_loginbname登陸名:
message.zh-cn.resx中:
res_loginbnameLoginName:

=========================================
然后在Golbal.asax中加入多语言设定支持代码(浏览器需要支持Cookie)

'=========================================
'Application_BeginRequestEvent
'
'TheApplication_BeginRequestmethodisanASP.NETeventthatexecutes
'oneachwebrequestintotheportalapplication.
'
'Thethreadcultureissetforeachrequestusingthelanguage
'settings
'
'=========================================
SubApplication_BeginRequest(ByValsenderAsObject,ByValeAsEventArgs)
Try
IfNotRequest.Cookies("resource")IsNothingOrRequest.Cookies("resource").Value=""Then
Thread.CurrentThread.CurrentCulture=CultureInfo.CreateSpecificCulture(Request.Cookies("resource").Value)
Else
Thread.CurrentThread.CurrentCulture=NewCultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
EndIf
Thread.CurrentThread.CurrentUICulture=Thread.CurrentThread.CurrentCulture
CatchexAsException
Thread.CurrentThread.CurrentCulture=NewCultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
EndTry
EndSub'Application_BeginRequest

在Web.Config中加入如下代码,用于设定编码和默认语种,在Global.asax中有调用:

=========================================
<globalizationrequestEncoding="utf-8"responseEncoding="utf-8"/>
<appSettings>
<addkey="DefaultCulture"value="zh-cn"/>
<!--zh-cn:簡體中文zh-tw:繁體中文en:英文-->
</appSettings>

=========================================
页面代码中使用多语言支持:

ImportsSystem.Resources

PublicClass类名
InheritsSystem.Web.UI.Page
ProtectedLocRMAsResourceManager=NewResourceManager("项目文件名.message",GetType(类名).Assembly)

PrivateSubPage_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
lblLogin.Text=LocRM.GetString("res_login")
EndSub
EndClass


=========================================

到这里多语言支持的工作就作完了,接下来自己去慢慢Key
message.zh-cn.resx'简体中文
message.zh-tw.resx'繁体中文
message.en'英文

这几个语言档吧