[英]Get active directory user group property in asp.net website - web.config
[英]asp.net web app - check user exist in Active Directory group
我有 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;
}
希望这可以帮助
哈维萨瑟
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.