Sitecore have since 7.5’ish fired events each time you manipulate the users in the .NET Membership database:
<event name="user:created"></event> <event name="user:deleted"></event> <event name="user:updated"></event> <event name="roles:usersAdded"></event> <event name="roles:usersRemoved"></event>
But I noticed that the user:created event was not fired. This is because I call the .NET Membership provider directly:
string userNameWithDomain = "extranet\\myuser"; string password = "somepassword"; string email = "email@example.com"; Membership.CreateUser(userNameWithDomain, password, email);
This call to Membership is not handled by Sitecore, thus no event is executed. To fix this I have found 2 solutions, one is not good and the other one is not good either.
SOLUTION 1: CALL THE SITECORE MEMBERSHIP PROVIDER DIRECTLY
This solution ignores the web.config settings and assume that you have not switched or overwritten the Membership Provider yourself. But it will fire the event though:
Sitecore.Security.SitecoreMembershipProvider provider = new Sitecore.Security.SitecoreMembershipProvider(); MembershipCreateStatus status = MembershipCreateStatus.Success; provider.CreateUser(usernameWithDomain, password, email, "", "", true, null, out status); if (status != MembershipCreateStatus.Success) throw new MembershipCreateUserException(status);
SOLUTION 2: RAISE THE EVENT YOURSELF
This solution requires you to raise the event yourself. You need encapsulate the call to create a user in your own class, and instruct everyone to never call Membership.CreateUser() directly:
MembershipUser user = Membership.CreateUser(usernameWithDomain, password, email); Event.RaiseEvent("user:created", user);
I can see from other blog posts that the user events are not the most widely used events in the Sitecore toolbox. If you have found another solution to this problem please let me know.
MORE TO READ: