从AD找到信息 [英] find info from AD

查看:57
本文介绍了从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 on
windows user name (strUserID). When I wrote in Windows Form, it return
value. 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 occurred
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: An
operations error occurred

Source Error:

Line 62: Dim UserFound As SearchResult = ADSearch.FindOne()

推荐答案

2005年2月4日星期五09:59:50 + 0800,Sakinah < SA ***** @ ambersoft.net>写道:

$ b $b¤大家好,
$ b $b¤
$ b $b¤我在下面写了代码,以便从Active Directory(AD)获取全名)基于
$ b $b¤windows用户名(strUserID)。当我在Windows窗体中写入时,它返回
$ b $b¤值。但我需要在Web窗体中显示但显示消息错误。任何想法?
$ b $b¤
$ b $b¤公共函数GetUserInfo(ByVal UserID As String)
$ b $b¤
$ b $b¤DimADEntry As New DirectoryServices.DirectoryEntry(" LDAP:// myDomain")
$ b $b¤
$ b $b¤DimADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
$ b $b¤
$ b $b¤昏暗ADSearchResult As System.DirectoryServices.SearchResult
$ b $b¤
$ b $b¤ADSearch.Filter=("(samAccountName =" ;& UserID&")")
$ b $b¤
$ b $b¤ADSearch.SearchScope= SearchScope.Subtree
$ b $b¤
$ b $b¤Dim UserFound As SearchResult = ADSearch.FindOne()
$ b $b¤
$ b $b¤如果Not IsNothing(UserFound)那么
$ b $b¤
$ b $b¤MsgBox(UserFound.GetDirectoryEntry()。Properties.It em(" name")。Value)
$ b $b¤
$ b $b¤结束如果< br $> $ b $b¤
$ b $b¤结束功能
$ b $b¤
$ b $b¤发生运营错误

¤描述:在执行
$ b $b¤当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取更多信息
$ b $b¤关于错误及其在代码中的起源。
$ b $b¤
$ b $b¤异常详情:系统.Runtime.InteropServices.COMException:
$ b $b¤操作错误发生
$ b $b¤
$ b $b¤源错误:
$ b $b¤
$ b $b¤第62行:Dim UserFound As SearchResult = ADSearch.FindOne()

您是否关闭了Web应用程序的匿名身份验证?

Paul ~~~ pc******@ameritech.net

Microsoft MVP(Visual基本的)
On Fri, 4 Feb 2005 09:59:50 +0800, "Sakinah" <sa*****@ambersoft.net> wrote:

¤ Hello guys,
¤
¤ I have write code below to get full name from Active Directory (AD) based on
¤ windows user name (strUserID). When I wrote in Windows Form, it return
¤ value. 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 occurred
¤ Description: An unhandled exception occurred during the execution of the
¤ current web request. Please review the stack trace for more information
¤ about the error and where it originated in the code.
¤
¤ Exception Details: System.Runtime.InteropServices.COMException: An
¤ operations error occurred
¤
¤ Source Error:
¤
¤ Line 62: Dim UserFound As SearchResult = ADSearch.FindOne()
Did you turn off Anonymous authentication for your web application?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)





我把这个配置放在web.config中,但是同样的错误


AUTHENTICATION

< authentication mode =" Windows" />


授权

<允许用户=" *" /> <! - 允许所有用户 - >

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!


I have put this configuration in web.config, but stil gor same error

AUTHENTICATION
<authentication mode = "Windows"/>

Authorization
<allow users="*"/> <!-- Allow all users -->
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


On Sun,2005年2月6日22:22:54 -0800,sakinah mohd isa< sa ***** @ ambersoft.net>写道:

$ b $b¤
$ b $b¤
$ b $b¤我已将此配置放在web.config中,但是同样的错误
$ b $b¤
$ b $b¤认证
$ b $b¤<认证模式=" Windows" />
$ b $b¤
$ b $b¤授权
$ b $b¤< allow users =" *" /> <! - 允许所有用户 - >
$ b $b¤


是的,但在IIS中,您是否为您的应用程序关闭了匿名身份验证?

Paul ~~~ pc******@ameritech.net

Microsoft MVP(Visual Basic)
On Sun, 06 Feb 2005 22:22:54 -0800, sakinah mohd isa <sa*****@ambersoft.net> wrote:

¤
¤
¤ I have put this configuration in web.config, but stil gor same error
¤
¤ AUTHENTICATION
¤ <authentication mode = "Windows"/>
¤
¤ Authorization
¤ <allow users="*"/> <!-- Allow all users -->
¤

Yes, but in IIS did you turn off anonymous authentication for your application?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)


这篇关于从AD找到信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆