470,607 Members | 2,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,607 developers. It's quick & easy.

Finding full name in Active Directory from a given username

Greetings,

I am writing an Intranet application in ASP.NET using VB.NET. I am
obtaining the username of the user with:

uName = User.Identity.Name, which is in the form of DOMAIN\username. I then
use substring to parse out just the username.

What I am trying to accomplish is getting the full name of the user by doing
a search in Active Directory, but I am failing at every turn. This code:

Dim de As DirectoryEntry
de = New DirectoryEntry("LDAP://Bestia/CN=" + uName) Bestia is the
name of our domain controller)
Dim ds As DirectorySearcher
ds = New DirectorySearcher(de)
Dim rs As SearchResult = ds.FindOne()

Returns this error:

[COMException (0x80072020): An operations error occurred]
This code:

Dim de As DirectoryEntry
de = New DirectoryEntry("LDAP://Bestia/CN=" + uName +
",DC=mainoffice") (mainoffice is the name of our domain)
Dim ds As DirectorySearcher
ds = New DirectorySearcher(de)

Returns this error:
[COMException (0x8007202b): A referral was returned from the server]
I'm new at doing this sort of coding and it seems like it should be a fairly
simple thing to do, but I can't get it to work. Can anybody help with this
problem? Also, if anybody knows of a simpler way to do this, I'm all ears.

Thanks in advance!

Mike
Jul 21 '05 #1
4 9491
On Thu, 14 Apr 2005 14:40:02 -0700, "Mike" <Mi**@discussions.microsoft.com> wrote:

§ Greetings,
§
§ I am writing an Intranet application in ASP.NET using VB.NET. I am
§ obtaining the username of the user with:
§
§ uName = User.Identity.Name, which is in the form of DOMAIN\username. I then
§ use substring to parse out just the username.
§
§ What I am trying to accomplish is getting the full name of the user by doing
§ a search in Active Directory, but I am failing at every turn. This code:
§
§ Dim de As DirectoryEntry
§ de = New DirectoryEntry("LDAP://Bestia/CN=" + uName) Bestia is the
§ name of our domain controller)
§ Dim ds As DirectorySearcher
§ ds = New DirectorySearcher(de)
§ Dim rs As SearchResult = ds.FindOne()
§
§ Returns this error:
§
§ [COMException (0x80072020): An operations error occurred]
§
§
§ This code:
§
§ Dim de As DirectoryEntry
§ de = New DirectoryEntry("LDAP://Bestia/CN=" + uName +
§ ",DC=mainoffice") (mainoffice is the name of our domain)
§ Dim ds As DirectorySearcher
§ ds = New DirectorySearcher(de)
§
§ Returns this error:
§
§
§ [COMException (0x8007202b): A referral was returned from the server]
§
§
§ I'm new at doing this sort of coding and it seems like it should be a fairly
§ simple thing to do, but I can't get it to work. Can anybody help with this
§ problem? Also, if anybody knows of a simpler way to do this, I'm all ears.
§
§ Thanks in advance!

If all you need is the FullName then use the WinNT provider instead of LDAP:

Dim DomainUser As String =
System.Security.Principal.WindowsIdentity.GetCurre nt.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)

Dim FullName As String = ADEntry.Properties("FullName").Value
Paul
~~~~
Microsoft MVP (Visual Basic)
Jul 21 '05 #2


"Paul Clement" wrote:
On Thu, 14 Apr 2005 14:40:02 -0700, "Mike" <Mi**@discussions.microsoft.com> wrote:

¤ Greetings,
¤
¤ I am writing an Intranet application in ASP.NET using VB.NET. I am
¤ obtaining the username of the user with:
¤
¤ uName = User.Identity.Name, which is in the form of DOMAIN\username. I then
¤ use substring to parse out just the username.
¤
¤ What I am trying to accomplish is getting the full name of the user by doing
¤ a search in Active Directory, but I am failing at every turn. This code:
¤
¤ Dim de As DirectoryEntry
¤ de = New DirectoryEntry("LDAP://Bestia/CN=" + uName) Bestia is the
¤ name of our domain controller)
¤ Dim ds As DirectorySearcher
¤ ds = New DirectorySearcher(de)
¤ Dim rs As SearchResult = ds.FindOne()
¤
¤ Returns this error:
¤
¤ [COMException (0x80072020): An operations error occurred]
¤
¤
¤ This code:
¤
¤ Dim de As DirectoryEntry
¤ de = New DirectoryEntry("LDAP://Bestia/CN=" + uName +
¤ ",DC=mainoffice") (mainoffice is the name of our domain)
¤ Dim ds As DirectorySearcher
¤ ds = New DirectorySearcher(de)
¤
¤ Returns this error:
¤
¤
¤ [COMException (0x8007202b): A referral was returned from the server]
¤
¤
¤ I'm new at doing this sort of coding and it seems like it should be a fairly
¤ simple thing to do, but I can't get it to work. Can anybody help with this
¤ problem? Also, if anybody knows of a simpler way to do this, I'm all ears.
¤
¤ Thanks in advance!

If all you need is the FullName then use the WinNT provider instead of LDAP:

Dim DomainUser As String =
System.Security.Principal.WindowsIdentity.GetCurre nt.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)

Dim FullName As String = ADEntry.Properties("FullName").Value
Paul
~~~~
Microsoft MVP (Visual Basic)


Hey Paul,

Thanks a lot for the help! What I get from this is "ASP.NET Machine
Account." I am guessing that is impersonation going on or something. What I
am looking for is the name of the user that is accessing the site. Any more
thoughts?

Thanks again!

Mike

Jul 21 '05 #3
On Fri, 15 Apr 2005 09:42:04 -0700, "Mike" <Mi**@discussions.microsoft.com> wrote:

§
§
§ "Paul Clement" wrote:
§
§ > On Thu, 14 Apr 2005 14:40:02 -0700, "Mike" <Mi**@discussions.microsoft.com> wrote:
§ >
§ > § Greetings,
§ > §
§ > § I am writing an Intranet application in ASP.NET using VB.NET. I am
§ > § obtaining the username of the user with:
§ > §
§ > § uName = User.Identity.Name, which is in the form of DOMAIN\username. I then
§ > § use substring to parse out just the username.
§ > §
§ > § What I am trying to accomplish is getting the full name of the user by doing
§ > § a search in Active Directory, but I am failing at every turn. This code:
§ > §
§ > § Dim de As DirectoryEntry
§ > § de = New DirectoryEntry("LDAP://Bestia/CN=" + uName) Bestia is the
§ > § name of our domain controller)
§ > § Dim ds As DirectorySearcher
§ > § ds = New DirectorySearcher(de)
§ > § Dim rs As SearchResult = ds.FindOne()
§ > §
§ > § Returns this error:
§ > §
§ > § [COMException (0x80072020): An operations error occurred]
§ > §
§ > §
§ > § This code:
§ > §
§ > § Dim de As DirectoryEntry
§ > § de = New DirectoryEntry("LDAP://Bestia/CN=" + uName +
§ > § ",DC=mainoffice") (mainoffice is the name of our domain)
§ > § Dim ds As DirectorySearcher
§ > § ds = New DirectorySearcher(de)
§ > §
§ > § Returns this error:
§ > §
§ > §
§ > § [COMException (0x8007202b): A referral was returned from the server]
§ > §
§ > §
§ > § I'm new at doing this sort of coding and it seems like it should be a fairly
§ > § simple thing to do, but I can't get it to work. Can anybody help with this
§ > § problem? Also, if anybody knows of a simpler way to do this, I'm all ears.
§ > §
§ > § Thanks in advance!
§ >
§ > If all you need is the FullName then use the WinNT provider instead of LDAP:
§ >
§ > Dim DomainUser As String =
§ > System.Security.Principal.WindowsIdentity.GetCurre nt.Name.Replace("\", "/")
§ > Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)
§ >
§ > Dim FullName As String = ADEntry.Properties("FullName").Value
§ >
§ >
§ > Paul
§ > ~~~~
§ > Microsoft MVP (Visual Basic)
§ >
§
§ Hey Paul,
§
§ Thanks a lot for the help! What I get from this is "ASP.NET Machine
§ Account." I am guessing that is impersonation going on or something. What I
§ am looking for is the name of the user that is accessing the site. Any more
§ thoughts?

You need to enable impersonation. I'm not sure what type of authentication your web application is
set up for.

http://msdn.microsoft.com/library/de...ersonation.asp
Paul
~~~~
Microsoft MVP (Visual Basic)
Jul 21 '05 #4


"Paul Clement" wrote:
On Fri, 15 Apr 2005 09:42:04 -0700, "Mike" <Mi**@discussions.microsoft.com> wrote:

¤
¤
¤ "Paul Clement" wrote:
¤
¤ > On Thu, 14 Apr 2005 14:40:02 -0700, "Mike" <Mi**@discussions.microsoft.com> wrote:
¤ >
¤ > ¤ Greetings,
¤ > ¤
¤ > ¤ I am writing an Intranet application in ASP.NET using VB.NET. I am
¤ > ¤ obtaining the username of the user with:
¤ > ¤
¤ > ¤ uName = User.Identity.Name, which is in the form of DOMAIN\username. I then
¤ > ¤ use substring to parse out just the username.
¤ > ¤
¤ > ¤ What I am trying to accomplish is getting the full name of the user by doing
¤ > ¤ a search in Active Directory, but I am failing at every turn. This code:
¤ > ¤
¤ > ¤ Dim de As DirectoryEntry
¤ > ¤ de = New DirectoryEntry("LDAP://Bestia/CN=" + uName) Bestia is the
¤ > ¤ name of our domain controller)
¤ > ¤ Dim ds As DirectorySearcher
¤ > ¤ ds = New DirectorySearcher(de)
¤ > ¤ Dim rs As SearchResult = ds.FindOne()
¤ > ¤
¤ > ¤ Returns this error:
¤ > ¤
¤ > ¤ [COMException (0x80072020): An operations error occurred]
¤ > ¤
¤ > ¤
¤ > ¤ This code:
¤ > ¤
¤ > ¤ Dim de As DirectoryEntry
¤ > ¤ de = New DirectoryEntry("LDAP://Bestia/CN=" + uName +
¤ > ¤ ",DC=mainoffice") (mainoffice is the name of our domain)
¤ > ¤ Dim ds As DirectorySearcher
¤ > ¤ ds = New DirectorySearcher(de)
¤ > ¤
¤ > ¤ Returns this error:
¤ > ¤
¤ > ¤
¤ > ¤ [COMException (0x8007202b): A referral was returned from the server]
¤ > ¤
¤ > ¤
¤ > ¤ I'm new at doing this sort of coding and it seems like it should be a fairly
¤ > ¤ simple thing to do, but I can't get it to work. Can anybody help with this
¤ > ¤ problem? Also, if anybody knows of a simpler way to do this, I'm all ears.
¤ > ¤
¤ > ¤ Thanks in advance!
¤ >
¤ > If all you need is the FullName then use the WinNT provider instead of LDAP:
¤ >
¤ > Dim DomainUser As String =
¤ > System.Security.Principal.WindowsIdentity.GetCurre nt.Name.Replace("\", "/")
¤ > Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)
¤ >
¤ > Dim FullName As String = ADEntry.Properties("FullName").Value
¤ >
¤ >
¤ > Paul
¤ > ~~~~
¤ > Microsoft MVP (Visual Basic)
¤ >
¤
¤ Hey Paul,
¤
¤ Thanks a lot for the help! What I get from this is "ASP.NET Machine
¤ Account." I am guessing that is impersonation going on or something. What I
¤ am looking for is the name of the user that is accessing the site. Any more
¤ thoughts?

You need to enable impersonation. I'm not sure what type of authentication your web application is
set up for.

http://msdn.microsoft.com/library/de...ersonation.asp
Paul
~~~~
Microsoft MVP (Visual Basic)


Hey Paul,

I set impersonation on by adding this line in the web.config file: <identity
impersonate="true" />, AND IT WORKS! I have the site set up for Windows
Authentication.

It's clear I have a lot to learn about this!

Thanks a lot for taking the time.

Mike
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mark | last post: by
reply views Thread by Ramnadh Nalluri | last post: by
2 posts views Thread by Cameron Frasnelly | last post: by
7 posts views Thread by Jason Reichenbach | last post: by
2 posts views Thread by NathanC | last post: by
reply views Thread by Kooki | last post: by
reply views Thread by Kooki | last post: by
2 posts views Thread by Lars Netzel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.