Skip to content

Instantly share code, notes, and snippets.

@adnanzameer
Created November 12, 2019 15:21
Show Gist options
  • Save adnanzameer/08cbe4e76182faccf0b88cf785ec96da to your computer and use it in GitHub Desktop.
Save adnanzameer/08cbe4e76182faccf0b88cf785ec96da to your computer and use it in GitHub Desktop.
Get Episerver User & User Roles
public IList<string> UserRoles()
{
IList<string> roles;
using (UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(new ApplicationDbContext<ApplicationUser>("EPiServerDB")))
{
ApplicationUser user = store.FindByNameAsync(PrincipalInfo.CurrentPrincipal.Identity.Name).GetAwaiter().GetResult();
roles = GetUserToRoles(store, user);
}
return roles;
}
private static IList<string> GetUserRoles(UserStore<ApplicationUser> store, ApplicationUser user)
{
IUserRoleStore<ApplicationUser, string> userRoleStore = store;
using (new RoleStore<IdentityRole>(new ApplicationDbContext<ApplicationUser>("EPiServerDB")))
{
return userRoleStore.GetRolesAsync(user).GetAwaiter().GetResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment