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/
  • 相关阅读:
    CSP 201612-3 权限查询 【模拟+STL】
    Vijos 1565 多边形 【区间DP】
    制作进度条(UISlider)
    制作按钮(Button)
    制作UI纹理(UI Texture)
    制作标签(Label)
    什么是UI控件
    制作精灵(UI Sprite)
    深度(Depth)概念
    2D UI和3D UI的工作原理
  • 原文地址:https://www.cnblogs.com/rock_chen/p/1323287.html
Copyright © 2011-2022 走看看