1.登陆验证代码 if (Membership.ValidateUser(userName.Text, password.Text))
{ if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(userName.Text, false); } else { FormsAuthentication.SetAuthCookie(userName.Text, false); } } else { Response.Write("Invalid UserID and Password"); }
MembershipCreateStatus ms;
MembershipUser newuser = Membership.CreateUser(TextBox1.Text, TextBox2.Text, TextBox4.Text, TextBox5.Text,TextBox6.Text,true, out ms); if (ms == MembershipCreateStatus.Success) { ProfileCommon p = (ProfileCommon)ProfileCommon.Create(newuser.UserName, true); Roles.AddUserToRole(TextBox1.Text, "usermember"); p.telphone = TextBox7.Text.Trim(); p.QQ = TextBox8.Text.Trim(); p.address = TextBox9.Text.Trim(); p.Save(); Roles.AddUserToRole(TextBox1.Text, "usergroup"); //添加新用户到usergroup角色组 Server.Transfer("login.aspx"); } else { string errorcode; switch (ms) { case MembershipCreateStatus.DuplicateUserName: errorcode = "Username already exists."; break; } } 对应的web.config中profile节点的配置如下; <profile enabled="true" defaultProvider="profileSqlMembershipProvider">
<providers> <add name="profileSqlMembershipProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="webshopConnectionString"/> </providers> <properties> <add name="telphone" type="String"/> <add name="QQ" type="String"/> <add name="address" type="String"/> </properties> </profile>
MembershipUserCollection col = Membership.FindUsersByName(this.TextBox1.Text);
if (col.Count == 0) Label1.Text = "恭喜您,可以注册"; else Label1.Text = "此用户已存在";
if (HttpContext.Current.User.Identity.IsAuthenticated == true)
{ Label1.Text = "您是注册用户,欢迎您的注册"; } else { Label1.Text = "您是匿名用户,请注册"; }
MembershipUser u;
u = Membership.GetUse(User.Identity.Name); Label1.Text = u.UserName; |