纯粹个人笔记,不代表任何技术发表
安装数据库:
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;
}