获取 ASP.NET MVC5 身份系统中的所有角色名称 [英] Get all role names in ASP.NET MVC5 Identity system

查看:27
本文介绍了获取 ASP.NET MVC5 身份系统中的所有角色名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVC5 使用新的身份系统.如何获取所有角色名称?

MVC5 uses a new Identity System. How can I get all role names?

我尝试通过 IdentityStore 访问它,但没有成功.

I try do access it via IdentityStore but without success.

推荐答案

我发现您可以通过 IdentityStore 实例使用 DbContext 并使用井-已知方法 .Set().

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

这对我有用:

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

这篇关于获取 ASP.NET MVC5 身份系统中的所有角色名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆