asp.net Web应用程序-检查用户是否存在于Active Directory组中

问题描述

|| 我有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)     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...