CreateUserWizard不会触发CompleteWizardStep

时间:2011-06-16 18:36:33

标签: asp.net membership-provider

我有一个自定义的CreateUserWizard,用户将其电子邮件作为用户名。此代码不会触发CompleteWizardStep1。我得到了我的成功消息,但会员资格模板仍处于活动状态,并且仅继续尝试创建另一个用户。

<fieldset>
        <legend>Create a User Account</legend>
        <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" AutoGeneratePassword="False" 
             BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="1px" 
            CancelDestinationPageUrl="~/" ContinueDestinationPageUrl="~/CustomerDetails.aspx" 
            CreateUserButtonText="Continue" Font-Names="Verdana" Font-Size="0.8em" 
            OnCreatingUser="CreateUserWizard1_CreatingUser">
            <SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" 
                VerticalAlign="Top" />
            <SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
            <ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" 
                BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" 
                ForeColor="#284775" />
            <NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" 
                BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" 
                ForeColor="#284775" />
            <HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" 
                Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" />
            <CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" 
                BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" 
                ForeColor="#284775" />
            <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <StepStyle BorderWidth="0px" />
            <WizardSteps>
                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" >
                   <ContentTemplate>
                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Email Address:</asp:Label><br />
                            <asp:TextBox ID="UserName" runat="server" MaxLength="32"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" EnableClientScript="true"
                            ErrorMessage="Email address is required." ToolTip="Email address is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="regEmail" ControlToValidate="UserName" Text="Invalid e-mail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Runat="server" /><br />                
                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label><br />
                            <asp:TextBox ID="Password" runat="server" TextMode="Password" 
                            MaxLength="16"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" EnableClientScript="true"
                            ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator><br />
                        <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label><br />
                            <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" 
                            MaxLength="16"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" EnableClientScript="true"
                            ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator><br />
                            <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                            ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                            ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                        <asp:TextBox ID="Email" runat="server" Visible="false" MaxLength="1"></asp:TextBox>
                    </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" >
                </asp:CompleteWizardStep>
            </WizardSteps>
        </asp:CreateUserWizard>
        <p align="center">      
            <asp:Label ID="ActionStatus" runat="server" CssClass="Important"></asp:Label> 
        </p>
    </fieldset>

 protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
        Page.Validate("CreateUserWizard1");
        if (!Page.IsValid)
        {
            return;
        }
        CreateUserWizard cuw = (CreateUserWizard)sender;
        cuw.Email = cuw.UserName;

        // Make sure that the user doesn't already belong to this role      
        if (Roles.IsUserInRole(cuw.UserName, "Customers"))
        {
            ActionStatus.Text = string.Format("User {0} already is a member.", cuw.UserName);
            return;
        }

        Roles.AddUserToRole(cuw.UserName, "Customers");

        // Display a status message      
        ActionStatus.Text = string.Format("User {0} was added.", cuw.UserName);
}

1 个答案:

答案 0 :(得分:0)

我很高兴没有人浪费时间试图通过我的代码。

原来我需要在AspNetSqlMembershipProvider中出现需要UniqueEmail =“false”。它设置为“true”,代码永远不会超过它。

感谢您的来访和欢呼。