2011-03-13 165 views
1

我正在使用MVC在Asp.net 4.0中开发Web应用程序。Active Directory的LDAP路径

在我的应用程序中,我使用Exchnage server 2007发送电子邮件。

我从交换服务器获取全局地址列表。

现在的问题是如何使用用户名,密码和域名来获取Active Directory的LDAP路径。

目前我正在做的是我使用DirectoryEntry的对象n传递LDAP服务器的路径,我事先知道。

但是,如果其他未知的技术服务器的凭据使用?

所以任何人都可以帮我理清这个问题吗?这是紧急的...

非常感谢你提前。

+0

我不熟悉交换全局地址列表,但我做了很多活动目录工作。如果你可以分享你的代码,并显示你硬编码的部分,我想我可以帮助使它独立于域 – 2011-03-13 15:52:39

回答

3

由于.NET 3.5及更高版本,您应该检查System.DirectoryServices.AccountManagement(S.DS.AM)命名空间。在这里阅读全部内容:

Managing Directory Security Principals in the .NET Framework 3.5

基本上,你可以定义域范围内,并可以轻松地查找用户和/或组AD:

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

// find yourself: 
UserPrincipal myself = UserPrincipal.Current; 

// find user by name 
UserPrincipal someoneElse = UserPrincipal.FindByIdentity("John Doe"); 

// get user's LDAP path 
if(someoneElse != null) 
{ 
    // the DN (DistinguishedName) is typically your full LDAP path to the object 
    // just prepend it with LDAP:// and you should be able to bind to it 
    string userDN = someoneElse.DistinguishedName; 

    // if you need the full LDAP path, you need to look at the underlying 
    // DirectoryEntry object from System.DirectoryServices: 
    string ldapPath = (someoneElse.GetUnderlyingObject() as DirectoryEntry).Path; 
} 

新S.DS.AM使它很容易与AD的用户和群体玩耍。因此,如果您从Exchange获得一些信息,例如用户的名字,你应该能够很容易地在AD中找到相应的UserPrincipal,并且从那里开始,做你需要做的一切。

0

我不熟悉.net。但是,我可以帮助在一定程度上解决这个问题

我猜你正在寻找用户的FDN

域控制器的名称为

 _ldap._tcp.<DNSDomainName> 
     _ldap._tcp.example.com 

的DNS SRV记录在这种情况下,它会告诉你运行AD的服务器的fqdn。 (基本上是ldap服务)。假设你得到,

 host.example.com 

然后做一个子树的LDAP搜索从DC =例如,DC = com的主机 'host.example.com' 上。 它会像,

ldapsearch -h host.example.com -b "dc=example,dc=com" -s sub samaccountname=username 

这会得到用户的LDAP路径(LDAP DN)。如果AD配置为不响应任何匿名请求,还有另一个问题。

但是,如果您正在寻找.Net解决方案,这可能没有任何意义。您可以尝试上述解决方案。

相关问题