473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

find info from AD

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()

Nov 22 '05 #1
10 4446
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)
Nov 22 '05 #2


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!
Nov 22 '05 #3
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)
Nov 22 '05 #4


Yes, I did turn off anonymous authentication in IIS.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #5
>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")


Usually, in a ASP.NET environment, you need to

a) specify the full LDAP path, including the server you are going to
hit (not just the domain), something like:

LDAP://myDC01.myDomain.com/dc=myDomain,dc=com

b) supply usable credentials for the call (can't use "anonymous"
binding since the ASP.NET app is running under the security context of
the ASP user, not your own user account). So you need to specify user
name and password in your "new DirectoryEntry()" call.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 22 '05 #6
On Mon, 07 Feb 2005 22:32:53 -0800, sakinah mohd isa <sa*****@ambersoft.net> wrote:

¤
¤
¤ Yes, I did turn off anonymous authentication in IIS.
¤

I think Marc might be correct. The domain reference when using the LDAP (Active Directory) provider
is different from the WinNT provider. If you don't know what the default naming context is for your
Active Directory domain try the following:

Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #7


Marc, stil got error under although i have put full LDAP path

Dim UserFound As SearchResult = ADSearch.FindOne()
-----

Paul,cannot get default name. error under

Dim DomainDN As String =
RootDSE.Properties("DefaultNamingContext").Value

-----
any sample code to get full name in AD. need help

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #8
>Marc, stil got error under although i have put full LDAP path
Dim UserFound As SearchResult = ADSearch.FindOne()


Show me the WHOLE code again, and show me the FULL LDAP PATH, as you
use it, too - thanks!

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 22 '05 #9
this is my full code to get full name in AD:
Public Function GetUserInfo(ByVal UserID As String)

Dim ADEntry As New
DirectoryServices.DirectoryEntry("LDAP://dc=ambersoft-internal,dc=local"
)
Dim ADSearch As New
System.DirectoryServices.DirectorySearcher(ADEntry )

Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree

'error here
Dim UserFound As SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
MsgBox
UserFound.GetDirectoryEntry).Properties.Item("name ").Value)
End If

End Function

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #10
>Public Function GetUserInfo(ByVal UserID As String)
Dim ADEntry As New
DirectoryServices.DirectoryEntry("LDAP://dc=ambersoft-internal,dc=local")
Dim ADSearch As New
System.DirectoryServices.DirectorySearcher(ADEntr y)
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree

'error here
Dim UserFound As SearchResult = ADSearch.FindOne()


And what exactly does the error say? The code looks okay from my
point of view - the only thing I can see is that the LDAP path used
for the "ADEntry" object would be invalid - is the "ADEntry" object
created okay? Or is it null / Nothing??

Also, if you want to use just a few select properties afterwards, it
would be helpful to add those to the list of attributes to the loaded
by the directory searcher, and then reference that directly, instead
of going the long route of calling .GetDirectoryEntry and then using
that DirEntry for your properties:

ADSearch.PropertiesToLoad.Add("name");
[and later on]
MsgBox UserFound.Properties.Item("name").Value
Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan Jones | last post by:
I'm writing a script to process a directory tree of images.  In each directory, I need to process each image and generate an HTML file listing all of the images and links to the subdirectories....
9
by: Simon Harris | last post by:
Hi All, Ok - I'll confess from the start, this is more about application logic that ASP, being an ASP programmer, I guessed you people might be able to help! :) I have built a room bookings...
1
by: Harsha | last post by:
I have been working on VB, ASP for quite a long time. Very Recently ( From past 1 month) I am managing a VC++ project. I am trying to use the code which i downloaded from the internet to find the...
1
by: t0M | last post by:
It's nearly impossible to find anything on this because of the Dictionary class, included within the dotnet framework, that pollutes any search results pertinent to my question. I want to be...
3
by: Dean Arpajian | last post by:
Looking to find info/ libs on creating (small) video files. Basically what I'm looking for is a tutorial for constructing a short video... (nothing nasty: output from a transmission line...
3
by: Sarah Smith via AccessMonster.com | last post by:
I am creating a database of documents that need to be worked on, are int eh proress of being worked on, and have been completed. Sometimes the same document (an updated version) comes back for more...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
12
by: smerf | last post by:
I have searched high and low (and even in some places I'd like to forget I ever saw) for the information that will tell me exactly how the Nat2Nat server for UltraVNC works (not just a vague...
10
by: OppThumb | last post by:
Hi, I've been searching this newsgroup for an answer to my question, and the closest I've come asks my question, but in reverse ("How to figure out the program from plan/package"). I've -- shall...
5
by: Mufasa | last post by:
We want to keep track of what OS/Browser people are using for our website. How can I find that out so that I can write it to a DB ? I know how to get it into the DB; I just need to know how to get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.