[英]how to access Active directory from WCF service
I've been asked to create a service in WCF, where input is user EMAIL-ID. 我被要求在WCF中创建服务,其中输入是用户EMAIL-ID。 there are many domains available in my server.
我的服务器中有很多可用域。 My WCF service is hosted in xxx domain.
我的WCF服务托管在xxx域中。
I need to get all yyy groups (Domain groups) for the user whose email matches.
Questions: 1. Can we connect to the Active directory from C# 2. How to get the User groups from C#. 问题:1.是否可以从C#连接到Active Directory?2.如何从C#获取用户组。 3. It is just for user validation, there is nothing to do with Active Directory.
3.仅用于用户验证,与Active Directory无关。 (simple search in AD groups)
(在广告组中进行简单搜索)
Since I'm new to this, even I dont know wheather it is possoble from C#. 由于我是新手,所以即使我不知道它在C#中也是可行的。 Early reply on this is highly appreciable.
对此,尽早答复是非常有意义的。 Thanks in advance.
提前致谢。
The System.DirectoryServices.AccountManagement
namespace is exactly what you need. System.DirectoryServices.AccountManagement
命名空间正是您所需要的。
Here's some code that should get you started. 这是一些应该帮助您入门的代码。
using System;
using System.DirectoryServices.AccountManagement;
namespace TestADCSharp
{
class Program
{
static void Main(string[] args)
{
PrincipalContext p = new PrincipalContext(
ContextType.Domain,
"your.domain"
);
UserPrincipal u = new UserPrincipal(p);
u.EmailAddress = "your@search.email";
PrincipalSearcher ps = new PrincipalSearcher(u);
PrincipalSearchResult<Principal> results = ps.FindAll();
foreach (Principal r in results) {
PrincipalSearchResult<Principal> groups = r.GetGroups();
Console.WriteLine("Groups:");
foreach (Principal g in groups) {
Console.WriteLine("\t" + g.Name);
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.