【发布时间】:2018-05-03 05:10:15
【问题描述】:
抱歉,我查看了链接“Find username from Active Directory using email id”,但这是针对 C# 的,我无法弄清楚如何在 Vb.net 中进行操作。
在我的 gridview 中,当我选择获取电子邮件 ID 并将其传递给 AD 以查找用户名的行时,但到目前为止,我无法弄清楚哪个命令将在 VB.net 中提供该详细信息
Protected Sub grdValidate_RowUpdating(sender As Object, e As EventArgs)
Dim strEmail As String = grdValidate.SelectedRow.Cells(2).Text
Dim ctx As New PrincipalContext(ContextType.Domain)
' find a user
Dim user As UserPrincipal = UserPrincipal.FindByIdentity(ctx, strEmail)
End Sub
我看到了这个属性“UserPrincipal.EmailAddress”,但 VS 甚至无法识别该命令。显然我进口了
Imports System.DirectoryServices
Imports System.DirectoryServices.AccountManagement
我正在尝试找到一个命令来传递电子邮件并匹配 AD 中的电子邮件 ID 并获取用户信息。
提前致谢
【问题讨论】:
-
任何称职的 VB 开发人员都可以阅读 C# 代码,即使他们不会编写。还有很多在线代码转换器,至少可以让您获得很大的帮助。先做你能做的,如果它不起作用,然后再发布。那个C#代码包含一个
using语句,和if语句和一个foreach语句,所有这些在VB中都有明显的等价物。如果您还没有编写包含这些代码的代码,那么您还没有尝试过,如果您还没有尝试过,那么在这里发布还为时过早。 -
对于
UserPrincipal类型,就像它对所有其他类型所做的那样,文档会告诉您它在哪个程序集中声明以及它是哪个名称空间的成员。您是否引用并导入了这些?如果不是,那么 VS 当然不会识别该类型。 -
您可能需要添加对
System.DirectoryServices的 .NET 引用 -
还有
System.DirectoryServices.AccountManagement