[英]get reference to the ASP.NET web.config customErrors section
[英]Get active directory user group property in asp.net website - web.config
在我的asp.net网站上,我在web.config中使用ActiveDirectoryRoleProvider。 我想在我的站点中获得活动目录用户组属性,例如(组名,组描述...)。 有什么办法可以使用web.config解决此问题?
任何帮助表示赞赏。
谢谢 !!
“我不知道是否可以通过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;
}
上面将为您提供用户所属的组的列表,您可以更深入地获取更多信息,但是我认为这就是您想要实现的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.