Monday, December 27, 2010

Disable Sitecore User Account on Creation

When Creating a new User in code via the CreateUserWizard or simply by calling Sitecore.Security.Account.User.Create() the user is approved by default.
To alter this behavior you will need to get the user and update the IsApproved field.

If you are simply using Sitecore.Security.Account.User.Create() then you just need to do the following:

                    // Create a new user in the system
                    newUser = User.Create(userName, password);

                    // Since we just created the user they should not be approved yet.
                    MembershipUser user = GetMembershipUserByUserName(userName);
                    user.IsApproved = false;

If you are using the wizard here is the event code.

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles CreateUserWizard1.CreatedUser

        ' Set Account to IsApproved=False
        Dim Usr As MembershipUser = Membership.GetUser(Me.CreateUserWizard1.UserName, True)
        Usr.IsApproved = False

    End Sub

I got this information from a forum post about
How to send confirmation email to newly registering user via CreateUserWizard

If you found this article useful be sure to pass it on. If you have any tips, tricks or resources you would like to share with the Guild please email them to

No comments:

Post a Comment