472,807 Members | 3,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 9719
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
Hi, given an Active Directory account as well as a Exchange MailBox can anyone show me how I link the two together in C# code? I want to be able to (Given a persons Active Directory Username)...
0
by: Ramnadh Nalluri | last post by:
Hi, I am creating DirectoryEntry in the C#.Net by taking the constructor DirectoryEntry("LDAP://<Domain>",<UserName>,<Pwd>,AuthenticationType.Sec ure) and creating the DirectoryEntry. But i...
2
by: Cameron Frasnelly | last post by:
Does anyone know how to get the full Distinguished Name from the Useraname using vb.net??? All the examples show how to manipulate user objects but they have the LDAP path hardcoded??? I need to...
4
by: Mike | last post by:
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...
7
by: Jason Reichenbach | last post by:
I've GOT to be missing something painfully obvious, here... I need to programmatically get the full human name of the current user on a local system, the same system upon which the app is...
2
by: NathanC | last post by:
'*********************************************** Dim MySearcher As New DirectorySearcher("LDAP://CN=Users,DC=corporate,DC=domainname,DC=com") ' Create a DirectorySearcher object. Dim resEnt As...
0
by: Kooki | last post by:
Hi, I am developing a small programme to add ACTIVE DIRECTORY users to another server. everything works fine .. I get the users from AD using LDAP but while adding users I need to get the user...
0
by: Kooki | last post by:
Hi, I am developing a small programme to add ACTIVE DIRECTORY users to another server. everything works fine .. I get the users from AD using LDAP but while adding users I need to get the user...
2
by: Lars Netzel | last post by:
Hi If I use the code: MsgBox(Environment.UserName) .... I get the username you log into windows with But how do I retrieve that Full Name of that useraccount?
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.