Search code examples
asp.netasp.net-membershipcreateuserwizard

CreateUserWizard not going to next step


I am using ASP.NET membership in a web application. I have the following code in a usercontrol:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="memberRegister.ascx.cs" Inherits="UmbracoMembership.usercontrols.memberRegister" %>
<asp:LoginView ID="lvRegister" runat="server">
    <AnonymousTemplate>
        <asp:CreateUserWizard ID="cwMember" runat="server"
            LoginCreatedUser="False" DisableCreatedUser="True"
            OnCreatedUser="cwMember_CreatedUser" ContinueDestinationPageUrl="~/Umbraco/">
            <WizardSteps>
                <asp:CreateUserWizardStep ID="cuwStep1" runat="server">
                    <ContentTemplate>

                        <div class="row1"><label>Username:</label><asp:TextBox ID="Username" runat="server" CssClass="inner-field"></asp:TextBox></div>
                        <div class="row1"><label>Full Name:</label><asp:TextBox ID="FullName" runat="server" CssClass="inner-field"></asp:TextBox></div>
                        <div class="row1"><label>Email:</label><asp:TextBox ID="Email" runat="server" CssClass="inner-field"></asp:TextBox></div>
                        <div class="row1"><label>Password:</label><asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="inner-field"></asp:TextBox></div>
                        <div class="row1"><label>Confirm Password:</label><asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" CssClass="inner-field"></asp:TextBox></div>

                    </ContentTemplate>
                     <CustomNavigationTemplate>
                            <div class="button-area">
                              <asp:Button ID="CreateUserButton" runat="server" Text="" CommandName="MoveNext" ValidationGroup="CreateUserWizard" CssClass="create-button"/>
                              </div>
                     </CustomNavigationTemplate>

                </asp:CreateUserWizardStep>
                <asp:CompleteWizardStep ID="cuwStep2" runat="server">
                    <ContentTemplate>

                        <div>Your account has been created, but still needs to be activated. <br />You will be recieving an activation email soon.</div>

                    </ContentTemplate>
                </asp:CompleteWizardStep>
            </WizardSteps>
        </asp:CreateUserWizard>
    </AnonymousTemplate>
</asp:LoginView>

And this is the code-behind:

public partial class memberRegister : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // is user is already logged on, redirect to home page (doesn't make sense to register when already logged in...)  

             if (umbraco.library.IsLoggedOn())  
                 Response.Redirect("~/");  

        }

        protected void cwMember_CreatedUser(object sender, EventArgs e)
        {
            CreateUserWizard cuw = (CreateUserWizard)sender;
            MembershipUser user = System.Web.Security.Membership.GetUser(cuw.UserName);
            if (user != null)
            {
                //create a new GUID
                string newUserGUID = System.Guid.NewGuid().ToString("N");

                //get profile for this user.
                UmbracoMembership.MemberProfile mp = MemberProfile.GetUserProfile(cuw.UserName);
                mp.AuthGuid = newUserGUID;
                mp.fullName = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("FullName")).Text;
                mp.email = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
                mp.Save();

                //add user to the site members group
                Roles.AddUserToRole(cuw.UserName, "RegisteredUsers");

                //Send email
                String fromAddress = "eample@bla.com";
                String toAddress = mp.email;
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

                smtp.EnableSsl = true;
                smtp.Credentials = new NetworkCredential("eample@bla.com", "1234");

                MailAddress _from = new MailAddress(fromAddress);
                MailAddress _to = new MailAddress(toAddress);
                MailMessage mMsg = new MailMessage(_from, _to);
                mMsg.Subject = "Welcome!";
                mMsg.Body = "Please click the following link to authorize your new account. " + "http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath.TrimEnd('/') + "/auth.aspx?a=" + user.UserName + "&b=" + newUserGUID;

                smtp.Send(mMsg);




                               }
        }
    }

}

For some reason after clicking "create user" and the postback happens, the user gets returned to the registration page instead of going to the complete page. I have tried everything. Been toying around with all kinds of settings for half a day now. Any ideas?


Solution

  • Well... it turns out that if you dont "handle" exceptions in the CreateUserWizard then nothing happens. The user is created and code-behind errors are not shown. I just added a try...catch and response.write(ex.message) and that gave me the error. The error itself was an issue with the profile manager. It appears that most of the examples on the net are made for Profile Provider in asp.net 2.0. In asp.net 4 you dont need to define in the web.config profile properties if you implement the ProfileBase class yourself and define the properties there.