zoukankan      html  css  js  c++  java
  • ASP.NET(3):多语言实现

    1.定义用户语言设置信息类,对用户选择的语言进行保存,可以用Session,这里选用的是Cookies.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using CommonUtility;

    /// <summary>
    ///ASPNET方式下为上下文语言环境提供语言设置对象
    /// </summary>

    public class ASPNETLocalizer : ILocalizer
    {
        HttpContext httpContext;
        
    /// <summary>
        
    /// 创建对象
        
    /// </summary>
        
    /// <param name="httpResponse">HTTP相应对象</param>

        public ASPNETLocalizer()
        
    {
            
    this.httpContext = HttpContext.Current;
        }


        
    ILocalizer 成员
    }

    由于对Cookies的访问有一定的限制,Request对象时候读,Response对象写,所以我们需要将用户选择语言的值保存在其它对象里面,可以保存在Session里,这里选择保存在HttpContext.Items中。

    2.定义HttpModule,每次访问的时候根据用户的设置来改变语言

    Code

    3.在Web.Config中添加记录

    <httpModules>
          
    <add name="MYModule" type="MYHttpModule"/>
    </httpModules>

    4.定义资源文件存取对象ResourceManager

    Code

    5.在需要赋值的地方,实例化赋值即可

    说明:初学ASP.NET,此方案很不成熟,自己练手用。

    ----------------------------------- http://www.cnblogs.com/rock_chen/
  • 相关阅读:
    Secure your iPhone with 6 digit passcode by upgrading to iOS9
    Threatening letter in Naver Line App
    Android Malware Analysis
    OGG目录清理数据
    RAC配置2个私网网卡使用HAIP服务
    sql调优脚本
    匿名内部类
    权限修饰符
    Android源码目录结构
    luffy项目:基于vue与drf前后台分离项目(1)
  • 原文地址:https://www.cnblogs.com/rock_chen/p/1323287.html
Copyright © 2011-2022 走看看