zoukankan      html  css  js  c++  java
  • 更改成员资格提供程序内的设置,使用户注册更适合实情

    一、使用web.config进行配置
    <system.web>
      <membership>
       <providers>
        <remove name="AspNetSqlMembershipProvider" />
        <add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"
         enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/"
         requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
         minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0"
         passwordAttemptWindow="10" passwordStrengthRegularExpression=""
         name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       </providers>
      </membership>
    其中:
    requiresQuestionAndAnswer项可设定是否必须要使用安全问题及安全问题回答;
    requiresUniqueEmail可设定是否一定要验证注册用户的Email格式;
    minRequiredPasswordLength可设定密码的最小长度;
    minRequiredNonalphanumericCharacters可设定密码中必须包含的非字母数字的个数;
    其实还有一个更简单的可视的方法可以修改WEB.CONFIG中注册设置,那就是使用IIS的站点的属性中的ASP.NET选项卡的"编辑配置"。



    二、增加注册用户还需要的一些项,如用户单位、年龄等(具体的可参照http://www.cnblogs.com/ahuang1118/archive/2006/06/22/433012.html)
    方法1:可使用成员数据库ASPNETDB.MDF中的aspnet_Profile表(这种方法在网上有许多讨论,这里不再复述)。
    方法2:在成员数据库ASPNETDB.MDF中新建一个表用于存储注册用户的其它信息,然后使用注册控件CreateUserWizard控件CreatedUser事件,在其实现方法中利用SQL语句完成增加注册用户的其它信息。如:

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            //添加用户到user组
            Roles.AddUserToRole(this.CreateUserWizard1.UserName, "user");
            MembershipUser mu = Membership.GetUser(this.CreateUserWizard1.UserName);
            string UserId = mu.ProviderUserKey.ToString();


            string  DanWei=((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxJBDanWei")).Text.Trim();
            string  Pone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxJBPhone")).Text.Trim();

            string sql = "INSERT INTO UserDetails(UserId, DanWei, Pone) VALUES ('" + UserId + "',";
            sql += "'" + DanWei + "','" + Pone  + "')";

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
            }
        }
    请注意,(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxJBDanWei")是获取在注册控件页面中所增加的控件。

  • 相关阅读:
    js 图表处理之Echar
    web.py url传参及获取
    算法理论基础
    Django------model基础
    python 数据分析----matplotlib
    python 数据分析----pandas
    python 数据分析----numpy
    ipythons 使用攻略
    Django----Request对象&Response对象
    Django---ModelForm详解
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/1229779.html
Copyright © 2011-2022 走看看