简体   繁体   English

如何在我的Web窗体中使用目录服务?

[英]How can I use Directory Services in my Web Form?

Basically I am creating an employee change request form and want to load up email groups in a selection listed (for add/removing memberships) I am working in Visual C# and trying to create a separate class that uses directory services to accomplish this. 基本上,我正在创建一个员工变更请求表单,并希望在列出的选择中加载电子邮件组(用于添加/删除成员资格),我正在Visual C#中工作,并试图创建一个单独的使用目录服务来完成此任务的类。 When I add the class to the App_Code folder it is no longer able to find the System.DirectoryServices and gives me an error. 当我将类添加到App_Code文件夹时,它不再能够找到System.DirectoryServices并给我一个错误。 What am I missing? 我想念什么?

If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. 如果您使用的是.NET 3.5及更高版本,则应签出System.DirectoryServices.AccountManagement (S.DS.AM)命名空间。 You'll need to add this to your project as a .NET reference. 您需要将其作为.NET参考添加到您的项目中。

Read all about it here: 在这里阅读所有内容:

Managing Directory Security Principals in the .NET Framework 3.5 在.NET Framework 3.5中管理目录安全主体

Basically, you can define a domain context and easily find users and/or groups in AD: 基本上,您可以定义域上下文并轻松找到AD中的用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}

The new S.DS.AM makes it really easy to play around with users and groups in AD: 新的S.DS.AM使得与AD中的用户和组玩起来非常容易:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用Exchange Web服务获取活动目录列表吗? - Can I use Exchange Web Services to get active directory listing? 我可以将WCF RIA服务与现有的Web API一起使用吗? - Can I use WCF RIA Services with existing web APIs? 如何确保无需计时器即可在Android应用程序中使用Azure移动服务? - How do I make sure I can use Azure Mobile Services in my Android app without a Timer? 如何在c#中查询Active Directory站点和服务? - How can I query Active Directory Sites and Services in c#? 当我更改实时服务器上的根目录时,我的 Web 服务页面未运行 asp.net - My Web Services page not running when i change root directory on live server asp.net 如何使用svchost.exe托管我自己的服务? - how can i use svchost.exe to host my own services? 如何在Quartz.net的作业类中使用某些服务和存储库? - How can I use some of my services and repositories in job class of Quartz.net? 如何在一个HttpServiceHost上托管两个或多个Web服务? - How can I host two or more web services on one HttpServiceHost? 如何提高调用Web服务的Excel UDF的性能? - How can I improve the performance of Excel UDF that call web services? 如何使用一种类方法使用2种Web服务? - How can I consume 2 web services with one class method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM