惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
C
Check Point Blog
博客园_首页
B
Blog
D
Docker
U
Unit 42
量子位
I
InfoQ
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
GbyAI
GbyAI
L
LangChain Blog
云风的 BLOG
云风的 BLOG
博客园 - Franky
美团技术团队
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
Vercel News
Vercel News
Recent Announcements
Recent Announcements
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Google DeepMind News
Google DeepMind News

博客园 - RevengeBoy

请求帮助 SQL 2005 master..xp_cmdshell 死锁问题 Rc4 encrypt in PeopleSoft - RevengeBoy CSS隐藏滚动条 - RevengeBoy - 博客园 程序员 2008的最后一天 大家有什么感想说出来吧 vista ie7 window.confirm() 取消按钮 失效 解决办法 - RevengeBoy 魔兽争霸III 1.20, 1.21 1.22 需要特定语言版本之Window 解决办法 css 换行 且不分割最后一个单词 - RevengeBoy 英文系统 中 中文成了乱码问题 sql 查询第5行到第7行 之间的行 反射技术与工厂方法 (using C#) 图片水印效果 - RevengeBoy - 博客园 Membership、MembershipUser和Roles类 上传大文件控件 显示进度条! (OnClientClick 和 OnClick 新页面回传值)(gridview中获取控件 获取值) [转]ASP.NET(C#)常用代码33例 电脑常识---[二] 最近创作---用户控件 蓦然回首 dropdownlist 下的 SelectedValue 问题
profile 的使用(更换皮肤转换语言)
RevengeBoy · 2007-07-12 · via 博客园 - RevengeBoy

纯粹个人笔记,不代表任何技术发表

安装数据库:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe

数据库起名为:MembershipDB

config 配置:

<configuration>
 <appSettings/>
 <connectionStrings>
    <add name="GSEGC_ConnectionString" connectionString="Data Source=localhost;Initial Catalog=MembershipDB;Integrated Security = true" providerName="System.Data.SqlClient" />
 </connectionStrings>
 <system.web>
    <membership>
      <providers>
        <remove name="AspNetSqlMembershipProvider" />
        <add connectionStringName="GSEGC_ConnectionString" enablePasswordRetrieval="false"
     enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/"
     requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
     minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1"
     passwordAttemptWindow="10" passwordStrengthRegularExpression=""
     name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </membership>
    <roleManager enabled="true">
      <providers>
        <remove name="AspNetSqlRoleProvider" />
        <add connectionStringName="GSEGC_ConnectionString" applicationName="/"
     name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </roleManager>
    <profile defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
      type="System.Web.Profile.SqlProfileProvider"
      connectionStringName="GSEGC_ConnectionString"
      applicationName="/"
      description="SqlProfileProvider for SampleApplication" />
      </providers>
      <properties>
        <add name="MyTheme" defaultValue="msn_cherryblossom"></add>      //定义MyTheme
        <add name="MyLanguage"  defaultValue="zh-cn"/>                                 //定义MyLanguage
      </properties>
    </profile>

.cs  下
using System.Threading;
using System.Globalization;

   protected void  Page_PreInit()// 获得皮肤事件
    {
        //if (Request.Form != null && Request.Form.Count > 0)
        //   this.Theme = this.Request.Form["DropDownList1"].Trim();

        // set the theme for the page. post-data is not currently loaded
        // use trace="true" to see the form collection
        ProfileCommon pc = new ProfileCommon();//匿名用户配置文件
        ProfileCommon pc2 = pc.GetProfile(Page.User.Identity.Name);//得到当前用户的配置文件
        this.Theme = pc2.MyTheme;
   }

    protected override void InitializeCulture() //转换语言事件
    {
        ProfileCommon pc = new ProfileCommon();//匿名用户配置文件
        ProfileCommon pc2 = pc.GetProfile(Page.User.Identity.Name);//得到当前用户的配置文件
        string UserCulture = pc2.MyLanguage;
        if (UserCulture != "")
        {
            //根据Session的值重新绑定语言代码
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(UserCulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(UserCulture);
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            ProfileCommon pc = new ProfileCommon();//匿名用户配置文件
            ProfileCommon pc2 = pc.GetProfile(Page.User.Identity.Name);//得到当前用户的配置文件
            string UserCulture = pc2.MyLanguage;
            if (UserCulture.ToUpper() == "EN-US")
            {
                pc2.MyLanguage = "zh-cn";
                pc2.Save();
            }
            else if (UserCulture.ToUpper() == "ZH-CN")
            {
                pc2.MyLanguage = "en-us";
                pc2.Save();
            }
            //重定向页面
            Response.Redirect(Request.Url.PathAndQuery);
        }
        catch (Exception)
        {
            throw;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Button2.Text = Resources.Language.BtnOkText;
    }