本文介绍了从AD找到信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我在下面编写代码,根据 windows用户名(strUserID)从Active Directory(AD)获取全名。当我在Windows窗体中写入时,它返回 值。但我需要在Web窗体中显示但显示消息错误。任何想法? 公共函数GetUserInfo(ByVal UserID As String) Dim ADEntry As New DirectoryServices.DirectoryEntry(" LDAP:// myDomain") Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry) Dim ADSearchResult As System.DirectoryServices.SearchResult ADSearch.Filter =("(samAccountName ="& UserID&")") ADSearch.SearchScope = SearchScope。 Subtree Dim UserFound As SearchResult = ADSearch.FindOne() 如果不是IsNothing(UserFound)那么 MsgBox(UserFound.GetDirectoryEntry()。Properties.It em(" name")。Value) 结束如果 结束功能 发生操作错误 描述:在执行 当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取更多信息 有关错误及其在代码中的起源。 异常详细信息:System.Runtime.InteropServices.COMException:发生了 操作错误 来源错误: 第62行:Dim UserFound为SearchResult = ADSearch.FindOne () Hello guys, I have write code below to get full name from Active Directory (AD) based onwindows user name (strUserID). When I wrote in Windows Form, it returnvalue. But I need to show in Web Form but display message error . any idea? Public Function GetUserInfo(ByVal UserID As String) Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://myDomain") Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry ) Dim ADSearchResult As System.DirectoryServices.SearchResult ADSearch.Filter = ("(samAccountName=" & UserID & ")") ADSearch.SearchScope = SearchScope.Subtree Dim UserFound As SearchResult = ADSearch.FindOne() If Not IsNothing(UserFound) Then MsgBox(UserFound.GetDirectoryEntry().Properties.It em("name").Value) End If End Function An operations error occurredDescription: An unhandled exception occurred during the execution of thecurrent web request. Please review the stack trace for more informationabout the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Anoperations error occurred Source Error: Line 62: Dim UserFound As SearchResult = ADSearch.FindOne() 推荐答案 这篇关于从AD找到信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 12:31