本文介绍了ASP.Net成员资格提供程序:自定义创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的教科书指出,有效密码的默认设置为要求您输入至少七个字符,其中一个字符为非字母数字".我肯定是这样做的.我收到的错误是提供的密码答案无效."这是aspx文件中的代码:

My textbook states that the default for a valid password, "requires that you enter at least seven characters with one of them being a non-alphanumeric." I am definitely doing that. The error I'm getting is, "The password answer supplied is invalid." Here is the code in the aspx file:

<div id="loginBlock">
    First Name: <asp:TextBox ID="fname" runat="server"></asp:TextBox>&nbsp;&nbsp;
    Last Name: <asp:TextBox ID="lname" runat="server"></asp:TextBox><br />
    Username: <asp:TextBox ID="userName" runat="server"></asp:TextBox><br />
    Password: <asp:TextBox ID="passwd" runat="server" TextMode="Password"></asp:TextBox><br />
    Confirm Password: <asp:TextBox ID="passwdConfirm" runat="server"
        TextMode="Password"></asp:TextBox>
    &nbsp;<asp:CompareValidator ID="validatePasswd"  CssClass="vaidator" ControlToValidate="passwdConfirm" ControlToCompare="passwd" runat="server" ErrorMessage="Passwords don't match! Re-enter."></asp:CompareValidator><br />
    Email:  <asp:TextBox ID="email" runat="server"></asp:TextBox><br />
    Confirm Email: <asp:TextBox ID="emailConfirm" runat="server"></asp:TextBox>
    &nbsp;<asp:CompareValidator ID="validateEmail"   CssClass="vaidator" ControlToValidate="emailConfirm" ControlToCompare="email" runat="server" ErrorMessage="Passwords don't match! Re-enter."></asp:CompareValidator><br />
    <asp:Button ID="submit" runat="server" Text="JOIN" onclick="submit_Click" /><br /><br />
    <asp:TextBox ID="loginError" CssClass="vaidator" runat="server" Width="300px" ReadOnly="True"
        BorderStyle="None" Font-Size="0.9em" Rows="2"></asp:TextBox>
</div>

这是按钮单击事件背后的代码:

And here is the code-behind button-click event:

 protected void submit_Click(object sender, EventArgs e)
        {
            try
            {
                Membership.CreateUser(userName.Text, passwdConfirm.Text, email.Text);
            }
            catch (MembershipCreateUserException)
            {
                loginError.Text = "Password must be a minumum of 7 characters and contain at least one non-alphanumeric character";
            }
        }

提前谢谢!

推荐答案

在安全配置中,您好像已经打开了疑问和答案的声音.检查您的web.config文件中的成员资格提供者部分,并检查requiresQuestionAndAnswer="false".

Sounds like you've got question and answer turned on in the security configuration. Check your web.config file for the membership provider section and check that requiresQuestionAndAnswer="false".

web.config文件中,应该有一个部分定义了成员资格提供程序设置,如下所示:

In your web.config file you should have a section defining the membership provider settings, something like this:

<membership>
  <providers>
    <clear/>
      <add name="AspNetSqlMembershipProvider" passwordStrengthRegularExpression="^.*(?=^[^\s]{8,32}$)(?=.*[a-zA-Z])(?=.*[\d]).*$" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnSTR" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="20" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/myApp"/>
  </providers>
</membership>

您需要设置的位是:

requiresUniqueEmail="false"

这篇关于ASP.Net成员资格提供程序:自定义创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:44