相关疑难解决方法(0)

确定用户是否在.NET 4.0应用程序的AD组中

我试图确定用户是否是内部ASP.NET 4.0应用程序的Active Directory(AD)组的成员.在用户不是AD组成员的情况下,下面的代码在最后一行(return语句)上抛出"尝试访问已卸载的appdomain"异常错误.

public static bool IsInADGroup(string userName, string groupName)
{
    var principalContext = new PrincipalContext(ContextType.Domain);
    UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName);
    if (userPrincipal == null)
        return false;

    GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, groupName);
    if (groupPrincipal == null)
        return false;

      return userPrincipal.IsMemberOf(groupPrincipal);
}
Run Code Online (Sandbox Code Playgroud)

有关如何修复或其他解决方法的任何想法?

.net c# directoryservices userprincipal

14
推荐指数
2
解决办法
8168
查看次数

标签 统计

.net ×1

c# ×1

directoryservices ×1

userprincipal ×1