简体   繁体   English

获取ASP.NET MVC5身份系统中的所有角色名称

[英]Get all role names in ASP.NET MVC5 Identity system

MVC5 uses a new Identity System. MVC5使用新的身份系统。 How can I get all role names? 我怎样才能获得所有角色名称?

I try do access it via IdentityStore but without success. 我尝试通过IdentityStore访问它但没有成功。

这更直观一些

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

I've found that you can use the DbContext via the IdentityStore instance and use the well-known method .Set<T>() . 我发现你可以通过IdentityStore实例使用DbContext并使用众所周知的方法.Set<T>()

This works for me: 这对我有用:

var identityStore = new IdentityStore();
foreach (var role in identityStore.DbContext.Set<Role>())
{
    Debug.WriteLine(role.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. 目前无法通过身份界面执行枚举样式方法,这将在未来的更新中定位管理方案(1.0 RTM之后),因此无法通过Identity API枚举所有用户或角色。 That said, you can always drop down to EF or whatever the store implementation is to directly enumerate the roles/users. 也就是说,您可以随时下载到EF或任何商店实现,以直接枚举角色/用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM