ASP CreateUserWizard Проверка регистрации участника провайдера - PullRequest
1 голос
/ 13 мая 2010

Я новичок в мире ASP и C #, я только что создал свою первую регистрационную форму, используя провайдер членства CreateUserWizard, и настроил валидаторы, которые отлично работают. Если имя пользователя будет взято, страница просто обновится, и никакая ошибка не будет замечательно, если кто-то может указать, где я могу пойти не так.

Вот мой текущий код:

SCRIPT

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
    /* User is created and setting extra parameters to profile */
    TextBox UserNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
    string username = UserNameTextBox.Text;

    MembershipUser User = Membership.GetUser(username);
    umbraco.cms.businesslogic.member.Member member = new umbraco.cms.businesslogic.member.Member((int)User.ProviderUserKey);

    /* Here you can access properties for the member */
    umbraco.cms.businesslogic.property.Property FullNameProperty = member.getProperty("fullname"); // Property alias
    TextBox FullNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FullName");
    FullNameProperty.Value = FullNameTextBox.Text;

    Roles.AddUserToRole(CreateUserWizard1.UserName, "NuneatonMember");
}
protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e)
{
    Response.Redirect("/member-area.aspx");
}

СОДЕРЖАНИЕ

<form runat="server">
 <asp:CreateUserWizard ID="CreateUserWizard1" OnContinueButtonClick="CreateUserWizard1_ContinueButtonClick" OnCreatedUser="CreateUserWizard1_CreatedUser" runat="server">
     <WizardSteps>
         <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
   <ContentTemplate>

    First Name :<asp:TextBox Runat="server" ID="FullName" CssClass="user_info"></asp:TextBox>
    <asp:RequiredFieldValidator ID="FullNameVal" runat="server" ControlToValidate="FullName" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    <br/>

    Last Name :<asp:TextBox Runat="server" ID="LastName" CssClass="user_info"></asp:TextBox>
    <asp:RequiredFieldValidator ID="LastNameVal" runat="server" ControlToValidate="LastName" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    <br/>

    Username :<asp:TextBox Runat="server" ID="UserName" CssClass="user_info"></asp:TextBox>
    <asp:RequiredFieldValidator ID="UserNameVal" runat="server" ControlToValidate="UserName" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    <br/>

    E-mail :<asp:TextBox Runat="server" ID="Email" CssClass="user_info"></asp:TextBox>
    <asp:RequiredFieldValidator ID="EmailVal" runat="server" ControlToValidate="Email" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator id="valRegEx" runat="server" ControlToValidate="Email" ValidationExpression=".*@.*\..*" ErrorMessage="* is not a valid e-mail address." ValidationGroup="CreateUserWizard1" display="dynamic"></asp:RegularExpressionValidator>
    <br/>

    Password :<asp:TextBox Runat="server" ID="Password" CssClass="user_info"></asp:TextBox>
    <asp:RequiredFieldValidator ID="PasswordVal" runat="server" ControlToValidate="Password" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    <br/>

    Confirm Password :<asp:TextBox Runat="server" ID="ConfirmPassword" CssClass="user_info"></asp:TextBox>
    <asp:RequiredFieldValidator ID="PConfirmVal" runat="server" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    <br/>

    <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ValidationGroup="CreateUserWizard1" ErrorMessage="Foul: Password and Confirmation Password do not match. Fix them."></asp:CompareValidator>

    <asp:literal runat="server" enableviewstate="true" id="FailureText"></asp:literal>

   </ContentTemplate>
  </asp:CreateUserWizardStep>
         <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"></asp:CompleteWizardStep>
     </WizardSteps>
</asp:CreateUserWizard> 

1 Ответ

1 голос
/ 13 мая 2010

Вам необходимо добавить обработчик ошибок.

<asp:CreateUserWizard ID="CreateUserWizard1" 
      OnContinueButtonClick="CreateUserWizard1_ContinueButtonClick"  
      OnCreatedUser="CreateUserWizard1_CreatedUser" runat="server" 
      OnCreateUserError="createUserWizard_CreateUserError">

И пример того, как вы могли бы это реализовать.

protected void createUserWizard_CreateUserError(object sender, CreateUserErrorEventArgs arguments)
{
    LogCreateUserError(arguments.CreateUserError, "no user info");
}

 private void LogCreateUserError(MembershipCreateStatus status, string username)
{
    string reasonText = status.ToString();

    switch (status)
    {
        case MembershipCreateStatus.DuplicateEmail:
        case MembershipCreateStatus.DuplicateProviderUserKey:
        case MembershipCreateStatus.DuplicateUserName:

            reasonText = "The user details you entered are already registered.";
            break;

        case MembershipCreateStatus.InvalidAnswer:
        case MembershipCreateStatus.InvalidEmail:
        case MembershipCreateStatus.InvalidProviderUserKey:
        case MembershipCreateStatus.InvalidQuestion:
        case MembershipCreateStatus.InvalidUserName:
        case MembershipCreateStatus.InvalidPassword:

            reasonText = string.Format("The {0} provided was invalid.", status.ToString().Substring(7));
            break;
        default:
            reasonText = "Due to an unknown problem, we were not able to register you at this time";
            break;

    }
   //DO whatever with it.. ....

}
...