Created
November 12, 2019 15:21
-
-
Save adnanzameer/08cbe4e76182faccf0b88cf785ec96da to your computer and use it in GitHub Desktop.
Get Episerver User & User Roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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