Windows身份验证可用的角色 [英] Roles available with Windows Authentication
问题描述
我正在尝试将角色身份验证添加到ASP.NET MVC应用程序中的控制器中的操作.代码看起来像这样:
I'm trying to add Roles authentication to an Action in a Controller in an ASP.NET MVC application. The code looks something like this:
[Authorize(Roles = "SomeRoleName")]
public ActionResult Index()
{
bool inRole = User.IsInRole("Admin");
如果我删除Authorize属性并在该代码示例的最后一行上放置一个断点,是否有一种方法可以检查对象并找出可用的角色?
If I remove the Authorize attribute and put a breakpoint on the last line in that code sample, is there a way that I can inspect the objects and find out what roles are available?
例如我在立即窗口中调用User.IsInRole("Admin),它将为我提供一个true/false值.如何访问可用角色的集合?
e.g. I call User.IsInRole("Admin) in the Immediate window and it will give me a true/false value. How can I access the collection of roles available?
推荐答案
如果不需要以编程方式进行此操作,但是您正在尝试确定需要指定的正确Windows组/角色,则可以使用此方法从命令行:
If you don't need to do this programatically, but you are trying to determine the correct Windows Groups/Roles that need to be specified, you can use this from the command line:
C:\> net group /domain (lists all Roles in the domain)
C:\> net user <username> /domain (lists info, including roles for a user)
否则,您将需要查询Active Directory的LDAP部分,或在DirectoryServices下使用某些内容.
Otherwise you will need to query the LDAP part of Active Directory, or use something under DirectoryServices.
看看这些网站可以通过C#访问Active Directory:
Take a look at these websites to access Active Directory via C#:
这篇关于Windows身份验证可用的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!