ASP.NET MVC 3:如何获得一个控制器方法用户的角色? [英] ASP.NET MVC 3: How to get User's Role in a Controller Method?

查看:236
本文介绍了ASP.NET MVC 3:如何获得一个控制器方法用户的角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够


  1. 获取当前验证用户的角色列表。

  2. 根据自己的角色过滤器提供给用户的数据。

我看到的方式来检查,如果用户是在一个特定的角色,但我不在乎他们参加什么样的作用。该数据库将知道什么样的角色被允许看到的数据。我需要提交这些角色的集合数据服务基于这些角色来过滤数据。

所以第一步就是如何获取在一个控制器方法当前用户相关联的所有角色?

编辑:

这似乎很好地工作了:

  Roles.GetRolesForUser(User.Identity.Name)

支持的答案仍然欢迎。


解决方案

  Roles.GetRolesForUser(User.Identity.Name)

I want to be able to

  1. Get a list of roles of the current authenticated user.
  2. Filter the data provided to that user based on their role.

I see ways to check if the user is in a particular role, but I don't care what role they participate. The database will know what roles are allowed to see what data. I need to submit a collection of these roles to the data service to filter the data based on those roles.

So first step is how do I get all roles associated with the current user in a controller method?

EDIT:

This seemed to work out nicely:

Roles.GetRolesForUser(User.Identity.Name)

Supporting answers still welcome.

解决方案

Roles.GetRolesForUser(User.Identity.Name)

这篇关于ASP.NET MVC 3:如何获得一个控制器方法用户的角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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