问题描述
||
我有asp.net Web应用程序,如何检查当前登录的用户(客户端)在特定的Active Directory组中。
谢谢
解决方法
请尝试以下方法。只需根据您的需要进行更改即可...
public List<string> GetGroupNames(string userName)
{
var pc = new PrincipalContext(ContextType.Domain);
var src = UserPrincipal.FindByIdentity(pc,userName).GetGroups(pc);
var result = new List<string>();
src.ToList().ForEach(sr => result.Add(sr.SamAccountName));
return result;
}
, 试试看(仅适用于ASP.NET,但Windows应用程序可使用类似的调用)
if (HttpContext.Current.User.IsInRole(\"RoleName\"))
{
return true;
}
else
{
return false;
}
希望这可以帮助
哈维·萨瑟(Harvey Sather)