开发者

asp.net web app - check user exist in Active Directory group

I have asp.net web ap开发者_如何学Pythonp, how to check the current logged in user (client) is in specific Active directory group. Thanks


Try this the following method. Just change it according to your needs...

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;
}


Try this (Only works in ASP.NET but similar calls are available for windows apps)

    if (HttpContext.Current.User.IsInRole("RoleName"))
    {
        return true;
    }
    else
    {
        return false;
    }

Hope this helps
Harvey Sather

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜