Get all role names in ASP.NET MVC5 Identity system

只谈情不闲聊 提交于 2019-11-30 01:50:04

I've found that you can use the DbContext via the IdentityStore instance and use the well-known method .Set<T>().

This works for me:

var identityStore = new IdentityStore();
foreach (var role in identityStore.DbContext.Set<Role>())
{
    Debug.WriteLine(role.Name);
}
joe

This is a bit more intuitive

var roles = dbContext.Roles.OrderBy(x => x.Name);

There's currently no way to do enumeration style methods via the identity interfaces, that will be coming in a future update targeting administration scenarios(post 1.0 RTM), so there's no way to enumerate all users or roles via the Identity APIs. That said, you can always drop down to EF or whatever the store implementation is to directly enumerate the roles/users.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!