By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,212 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,212 IT Pros & Developers. It's quick & easy.

active directory query using directorysearcher

P: n/a
I am having a weird problem. I am trying to use the following code to query
active directory.

Function IsExistInAD(ByVal loginName As String) As Boolean
Dim userName As String = ExtractUserName(loginName)
Dim search As DirectorySearcher = New DirectorySearcher
search.Filter = String.Format("(SAMAccountName={0})", userName)
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne
If result Is Nothing Then
Return False
Else
Return True
End If
End Function

Where I am passing in DOMAIN\username. Now, the problem is that it works
fine on windows forms. It searches AD and returns true if the username exists
and false if the username doesnt exit in the domain.

But now I have to do the same thing on a webform. And it wont work.
I get:

Server Error in '/WaiversEngagements' Application
--------------------------------------------------------------------------------

The specified domain either does not exist or could not be contacted

Any ideas????

Any and all help would be greatly appreciated.

Thanks.
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Tash,

It seems that the ASPNET account don't have enough permission. You can try
to use impersonate in web.config:

<identity impersonate="true" userName="ImpersonatedID"
password="Password" />

HTH

Elton Wang
el********@hotmail.com
"Tash" wrote:
I am having a weird problem. I am trying to use the following code to query
active directory.

Function IsExistInAD(ByVal loginName As String) As Boolean
Dim userName As String = ExtractUserName(loginName)
Dim search As DirectorySearcher = New DirectorySearcher
search.Filter = String.Format("(SAMAccountName={0})", userName)
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne
If result Is Nothing Then
Return False
Else
Return True
End If
End Function

Where I am passing in DOMAIN\username. Now, the problem is that it works
fine on windows forms. It searches AD and returns true if the username exists
and false if the username doesnt exit in the domain.

But now I have to do the same thing on a webform. And it wont work.
I get:

Server Error in '/WaiversEngagements' Application.
--------------------------------------------------------------------------------

The specified domain either does not exist or could not be contacted

Any ideas????

Any and all help would be greatly appreciated.

Thanks.

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.