网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.中国地区三级联动下拉菜单代码和.
..NET下生产图片验证码.
.ASP.NET中的HTTP模块和处理程序.
.URL编码处理.
.怎样在Web开发中完美控制IE标题栏.
.在ASP.NET程序中创建唯一序号.
.asp.net 2.0 中加密web.config 文.
.ASP.NET中利用VWD操作数据库.
.Asp.net(C#)多文件上传.
.asp.net 2.0 上传控件的使用.
.将Asp.net从VS2003以及VS2002工程.
.Asp.net Ajax 1.0 异步回调时,服.
.通过避免下列10个常见ASP.NET缺陷.
..NET 连接到 Oracle的oci.dll加载.
.使用HttpWebRequest向网站模拟上.
.ASP.NET 2.0的视图状态持久性机制.
.使用函数传递参数来执行数据库操.
.Asp.net生成htm静态文件的两种途.
.用Repeater控件显示数据.
..NET在SQL Server中的图片存取技.

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

发表日期:2004-9-12


首先建立语言档,在项目中加入.resx文件

例如:
message.zh-cn.resx '简体中文
message.zh-tw.resx '繁体中文
message.en         '英文
..............

============================================
然后利用Name --Value 键值对 填入你要在页面上显示的语言
如:
                                      name                      value
message.zh-cn.resx中:  res_loginbname            登陆名 :
message.zh-tw.resx中:  res_loginbname            登陸名 :
message.zh-cn.resx中:  res_loginbname            Login Name :

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

    '========================================
    ' Application_BeginRequest Event
    '
    ' The Application_BeginRequest method is an ASP.NET event that executes
    ' on each web request into the portal application. 
    '
    ' The thread culture is set for each request using the language
    ' settings
    '
    '=========================================
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Try
            If Not Request.Cookies("resource") Is Nothing Or Request.Cookies("resource").Value = "" Then
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.Cookies("resource").Value)              
            Else
                Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
            End If
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
        Catch ex As Exception
            Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
        End Try
    End Sub 'Application_BeginRequest

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

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

 

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

Imports System.Resources

Public Class 你的类名
    Inherits System.Web.UI.Page
    Protected LocRM As ResourceManager = New ResourceManager("项目文件名.message", GetType(类名).Assembly)

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblLogin.Text = LocRM.GetString("res_login")
    End Sub
End Class


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

这几个语言档吧,这是一个痛苦的回忆!


语言的后缀 如:
zh-cn'简体中文
zh-tw'繁体中文
en   '英文

可以参考 IE选项---网际网络设定--〉一般选项卡语言--〉新增里边的内容

上一篇:在ASP.NET中如何用C#.NET实现基于表单的验证 人气:16557
下一篇:ASP.NET 2.0里轻松获取数据库连接统计数据 人气:13292
浏览全部ASP.NET的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐