ASP.NET Active Directory C# 字段规范
我们这里有一个活动目录。提供了用户的唯一用户 ID,我需要访问与该用户 ID 相关的组织->经理->名称属性。基本上,这将用于向提交请求的人的经理发送批准表。
知道如何做到这一点吗?
We've got an active directory here. provided the unique user id of the user, I need to access the organization->manager->name attribute related to that userid. Basically this will be used to send an approval form to the manager of the person submitting request.
Any idea how this could be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用以下代码:
但您也可以找到 在这篇文章中其他方式来搜索绑定到活动目录。
You can use the following code :
But you can also find in this post other ways to seach bind to Active-directory.
由于您使用的是 .NET 3.5 及更高版本,因此您应该检查
System.DirectoryServices.AccountManagement
(S.DS.AM) 命名空间。在这里阅读所有相关内容:基本上,您可以定义域上下文并轻松查找 AD 中的用户和/或组:
新的 S.DS.AM 使在 AD 中使用用户和组变得非常容易!
我不是 100% 确定您在具体情况下想要做什么...
UserPrincipal
有一个EmployeeId
属性 - 这是您想要搜索的内容吗?Since you're on .NET 3.5 and up, you should check out the
System.DirectoryServices.AccountManagement
(S.DS.AM) namespace. Read all about it here:Basically, you can define a domain context and easily find users and/or groups in AD:
The new S.DS.AM makes it really easy to play around with users and groups in AD!
I'm not 100% sure what you want to do in your concrete case... the
UserPrincipal
has anEmployeeId
property - is that what you want to search for?使用
System.DirectoryServices.DirectoryEntry
< /a> 类来读出用户对象的适当属性。DirectoryEntry
的构造函数要求您拥有用户的 LDAP 路径。尽管 IIS 更喜欢仅传递 SAM 帐户名,但获取 LDAP 路径通常很棘手。如果您提供有关您所拥有的用户 ID 的更多详细信息,则可以更轻松地为您指明正确的方向。为此,运行 ASP.NET 应用程序的帐户需要对 AD 具有读取权限,而默认情况下可能没有该权限。如果 Web 服务器属于 AD,则将应用程序池更改为在“NetworkService”下运行是最简单的方法。然后,ASP.NET 应用程序将使用服务器的 MACHINE$ 帐户来访问 AD。
Use the
System.DirectoryServices.DirectoryEntry
class to read out the appropriate property of the user object. The constructor ofDirectoryEntry
requires that you have an LDAP path to the user. Getting the LDAP path can often be tricky though as IIS prefers handing over the SAM account name only. If you provide more details of what the user id you have looks like it is easier to point you in the right direction.To do this the account which runs the ASP.NET application needs read access to the AD, which probably doesn't have by default. Changing the application pool to run under "NetworkService" is the easiest way if the web server belongs to the AD. The ASP.NET app will then use the MACHINE$ account of the server to access the AD.