C# 获取asp.net网站-web.config中的active directory用户组属性
在我的asp.net网站中,我在web.config中使用ActiveDirectoryRoleProvider。我想在我的站点中获取active directory用户组属性,如(组名称、组描述…)。有没有办法通过使用web.config来解决这个问题 感谢您的帮助C# 获取asp.net网站-web.config中的active directory用户组属性,c#,asp.net,iis-7,active-directory,web-config,C#,Asp.net,Iis 7,Active Directory,Web Config,在我的asp.net网站中,我在web.config中使用ActiveDirectoryRoleProvider。我想在我的站点中获取active directory用户组属性,如(组名称、组描述…)。有没有办法通过使用web.config来解决这个问题 感谢您的帮助 谢谢 '我不知道您是否可以通过web.config设置获取此信息,但您可以从System.DirectoryServices.AccountManagement命名空间获取此信息。(如果按用户查找) 您可以将域名存储在web.co
谢谢 '我不知道您是否可以通过web.config设置获取此信息,但您可以从System.DirectoryServices.AccountManagement命名空间获取此信息。(如果按用户查找) 您可以将域名存储在web.config的appsettings中,并执行以下操作
private static PrincipalContext _ctx = new PrincipalContext(ContextType.Domain, System.Configuration.ConfigurationManager.AppSettings["DomainName"]);
public List<string> UserGroups(string userName)
{
List<string> ret = new List<string>();
using (UserPrincipal user = UserPrincipal.FindByIdentity(_ctx, userName))
{
if (user != null)
{
foreach (Principal p in user.GetAuthorizationGroups())
{
ret.Add(p.Name);
}
}
}
return ret;
}
private static PrincipalContext\u ctx=new PrincipalContext(ContextType.Domain,System.Configuration.ConfigurationManager.AppSettings[“DomainName]”);
公共列表用户组(字符串用户名)
{
List ret=新列表();
使用(UserPrincipal user=UserPrincipal.FindByIdentity(_ctx,userName))
{
如果(用户!=null)
{
foreach(user.GetAuthorizationGroups()中的主体p)
{
ret.Add(p.Name);
}
}
}
返回ret;
}
上面的内容会给你一个用户所属组的列表,你可以更深入地了解并获得更多信息,但我认为这就是你想要实现的目标