Try our conversational search powered by Generative AI!

Registers a callback that will be invoked to create a role using UIRoleProvider



Has anyone implemented a solution for registering a callback if and when we create role in CMS Access Groups (UIRoleProvider) ?

In CMS 11, we used to register using Owin CreatePerOwinContext<UIRoleProvider> But I could not figure out a way to implement the same on CMS 12. 

Any help would be appreaciated.

~ Sujit

Feb 08, 2024 16:05

Hi Sujit

I'm not 100% sure what's the challenge you're facing in CMS 12. It would be good to have some pseduo code to describe how you implement the callback in CMS 11

In CMS 12, UIRoleProvider abstract class is still there, you can implement you custom UIRoleProvider and override "CreateRoleAsync" method to intercept anything you would like to perform. 

Feb 09, 2024 1:29

Hi Vincent,

Here is how we used to register a callback using OWIN. Hope this helps.

public static IAppBuilder RegisterCustomRoleProvider(this IAppBuilder app)
//CustomIdentityRoleProvider is an implementation of  class ApplicationRoleProvider<TUser> where TUser : IdentityUser, IUIUser
//CommerceIdentityUser is an implementation of class IdentityUser & IUIUser
			app.CreatePerOwinContext<UIRoleProvider>((o, context) =>
				new CustomIdentityRoleProvider<CommerceIdentityUser>(
					context.Get<ApplicationUserManager<CommerceIdentityUser>>, context.Get<ApplicationRoleManager<CommerceIdentityUser>>));

			return app;
Feb 09, 2024 15:30

Found the fix in just one line. 

services.AddTransient<UIRoleProvider, CustomIdentityRoleProvider<CommerceIdentityUser>>();
Feb 09, 2024 18:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.