获取属于使用授权管理器角色的用户列表器(AzMan) [英] Get list of users belonging to a role using Authorization Manager (AzMan)
问题描述
使用ASP.NET(C#)我已经设置了授权管理器,让我在网站上处理的作用。将用户添加到角色很简单 Roles.AddUserToRole(DOMAIN \\\\用户名,角色)
。不过,我想列出属于一个角色的用户,但由于它们被存储为SID的,显示它们不会是有帮助的。要得到,我想XML将不得不使用的用户来说,虽然是有可能使用COM互操作既做到这一点,得到的用户名?无论哪种方式,我怎么能得到用户属于一个角色?
到管理角色该表将基本上是这样的:
角色用户
---- ----
管理域\\用户名[删除]
DOMAIN \\而UserName2 [删除]
[添加用户文本框]
新闻DOMAIN \\ USERNAME3 [删除]
[添加用户文本框]
发现这样做的一种方式(IAzRole接口,感谢Bermo),通过对每个角色的MembersName财产循环。无需映射回Windows帐户,除非你需要得到比用户名以上。
设置角色中的文章详细介绍:如何:使用授权管理器(AzMan)在ASP.NET 2.0中
在Visual Studio项目到AzMan的COM库中添加引用(azroles 1.0类型库)。然后加入使用AZROLESLib;
。添加<表ID =form1的=服务器>
,然后在Page_Load中:
AzAuthorizationStoreClass AzManStore =新AzAuthorizationStoreClass();
字符串CONNSTRING = ConfigurationManager.ConnectionStrings [AuthorizationServices]的ConnectionString。
字符串路径=使用Server.Mappath(connString.Substring(MSXML://。长度));
AzManStore.Initialize(0,MSXML://+路径,NULL);
IAzApplication azApp = AzManStore.OpenApplication(APPNAME,NULL);
占位符P =新的占位符();
StringBuilder的SB =新的StringBuilder();
sb.Append(&所述; UL>中);
的foreach(在azApp.Roles IAzRole角色)
{
sb.Append(<立GT;);
sb.Append(role.Name);
sb.Append(&所述; UL>中);
的foreach(对象成员(对象[])role.MembersName)
{
sb.Append(<立GT;);
sb.Append(会员);
sb.Append(< /李>);
}
sb.Append(&下; / UL>中);
sb.Append(< /李>);
}
sb.Append(&下; / UL>中);
p.Controls.Add(新LiteralControl(sb.ToString()));
form1.Controls.Add(P);
这显示在每个角色的角色和成员名单。
Using ASP.NET (C#) I have set up Authorization Manager to allow me to handle roles on a website. Added users to roles is simple Roles.AddUserToRole("DOMAIN\\UserName", "role")
. However I want to list the users belonging to a role, but since they are stored as SID's, displaying them would not be that helpful. To get the users, I am thinking XML would have to be used, although is it possible to use COM Interop to both do that and get the user name? Either way, how can I get the users belonging to a role?
The table to manage roles would basically be like this:
Role User
---- ----
admin DOMAIN\UserName [delete]
DOMAIN\UserName2 [delete]
[add user text box]
news DOMAIN\UserName3 [delete]
[add user text box]
Found a way of doing it (IAzRole Interface, thanks to Bermo), looping through the MembersName property on each role. No need to map back to a windows account, unless you need to get more than the user name.
Setup roles as detailed in article: How To: Use Authorization Manager (AzMan) with ASP.NET 2.0
In Visual Studio Project add reference to AzMan COM library (azroles 1.0 Type Library). Then add using AZROLESLib;
. Add <form id="form1" runat="server">
, then in Page_Load:
AzAuthorizationStoreClass AzManStore = new AzAuthorizationStoreClass();
string connString = ConfigurationManager.ConnectionStrings["AuthorizationServices"].ConnectionString;
string path = Server.MapPath(connString.Substring("msxml://".Length));
AzManStore.Initialize(0, "msxml://" + path, null);
IAzApplication azApp = AzManStore.OpenApplication("AppName", null);
PlaceHolder p = new PlaceHolder();
StringBuilder sb = new StringBuilder();
sb.Append("<ul>");
foreach (IAzRole role in azApp.Roles)
{
sb.Append("<li>");
sb.Append(role.Name);
sb.Append("<ul>");
foreach (object member in (object[])role.MembersName)
{
sb.Append("<li>");
sb.Append(member);
sb.Append("</li>");
}
sb.Append("</ul>");
sb.Append("</li>");
}
sb.Append("</ul>");
p.Controls.Add(new LiteralControl(sb.ToString()));
form1.Controls.Add(p);
This displays a list of roles and members in each role.
这篇关于获取属于使用授权管理器角色的用户列表器(AzMan)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!