Running Custom Logic When User Is Added to a Role

Do you need to run custom logic when a user is added to a role? Simple!

You can do this using Sitecore's eventing engine by creating event handlers for the roles:usersAdded event, the roles:usersAdded:remote event, or both.

The roles:usersAdded event is raised when users have been added to one or more roles on the environment. In other words, if you have a single-server environment then this is the event that you will want to tie into. Additionally, if you have a split CM/CD environment and you want to listen for users being added to roles on the same server that you added the handler on then this is the event you will want to use.

In contrast, the roles:usersAdded:remote event is used on the CM server when you have a split CM\CD environment and want to listen for this event occurring on the CD.

While it may seem a little confusing that you have a :remote event for adding users to roles, when roles are stored in the Core DB which is shared by both the CM and CD, the events are fired from the code, so having a :remote listens for the code on the CD environment that adds users to roles.

Post a Comment