看看用户是Active Directory组的C#+ Asp.net的一部分 [英] See if user is part of Active Directory group in C# + Asp.net

查看:114
本文介绍了看看用户是Active Directory组的C#+ Asp.net的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来看看,如果用户是Active Directory组的从我的.Net 3.5 asp.net C#应用程序的一部分。

I need a way to see if a user is part of an active directory group from my .Net 3.5 asp.net c# application.

我使用的是标准的LDAP认证例如关闭MSDN,但我实在不明白怎么要检查一组。

I am using the standard ldap authentication example off of msdn but I don't really see how to check against a group.

推荐答案

3.5和<一href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx">System.DirectoryServices.AccountManagement这是一个有点清洁:

With 3.5 and System.DirectoryServices.AccountManagement this is a bit cleaner:

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

这篇关于看看用户是Active Directory组的C#+ Asp.net的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆