Getting the full name (not user name) of a user on an aspx webpage

N

Novice

Hi all, I'm trying to display the full name of a windows user (not
their login name) using System.DiretoryServices.

However, I keep getting the following error:
Exception Details: System.Runtime.InteropServices.COMException: The
network path was not found

I'm using Windows 2000.

I'm assigning the DirectoryEntry object Path variable:
WinNT://myDomain/myUserName

Note: I've replaced my actual domain and user name with myDomain and
myUserName. But in my source code they are the actual domain and user
name that I use to log into my machine.

However, when I make the myDomain portion of the above equal to my
machine's domain name, a different error message appears:
Exception Details: System.Runtime.InteropServices.COMException: The
group name could not be found

The code I'm using is fairly simple.

I have the following at the top of my aspx page:
<%@ Assembly name="System.DirectoryServices, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>
<%@ Import Namespace="System.DirectoryServices" %>

Then I have the following function:
Private Function GetUserName() as String
Dim FullName as string
Dim objUser as new DirectoryEntry
objUser.Path = "WinNT://myDomain/myUserName"
FullName = ObjUser.Name
Return FullName
End Function

Once I get the above working, I would like to start making use of:
User.Identity.Name

so that any user coming to my webpage will get their full name
appearing on the webpage.

Thanks,
Novice
 
K

Kevin Spencer

WinNT specifies the local machine. Try using LDAP instead.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
S

Steve C. Orr [MVP, MCSD]

Try this code. (also set <identity impersonate="true"/> in your web.config)

string Domain_Slash_User = Context.User.Identity.Name;
Domain_Slash_Machine = Domain_Slash_Machine.Replace(@"\",
@"/");
string queryString = @"WinNT://" + Domain_Slash_Machine;

DirectoryEntry obDirEntry = new DirectoryEntry
(queryString);
System.DirectoryServices.PropertyCollection coll =
obDirEntry.Properties;

object obVal = coll["FullName"].Value;
_User = obVal.ToString();

Session.Add("UserFullName", _User);
 
G

Guest

A couple of comments
1. Where did you get the variable "Domain_Slash_Machine" from? Did you mean to use Domain_Slash_User everywhere you wrote Domain_Slash_Machine
2. Is that Visual Basic, C# or just pseudo-code (i.e. the "string" class with a lower case "s", etc)

Thanks
Novic

----- Steve C. Orr [MVP, MCSD] wrote: ----

Try this code. (also set <identity impersonate="true"/> in your web.config

string Domain_Slash_User = Context.User.Identity.Name
Domain_Slash_Machine = Domain_Slash_Machine.Replace(@"\"
@"/")
string queryString = @"WinNT://" + Domain_Slash_Machine

DirectoryEntry obDirEntry = new DirectoryEntr
(queryString)
System.DirectoryServices.PropertyCollection coll
obDirEntry.Properties

object obVal = coll["FullName"].Value
_User = obVal.ToString()

Session.Add("UserFullName", _User)
 
G

Guest

Sorry, but I don't really understand - do I just put
LDAP://domain/userNam
?

Or do I have to specify the LDAP server for my network

Thanks
Novice
 
N

Novice

Novice said:
Sorry, but I don't really understand - do I just put:
LDAP://domain/userName
??

Or do I have to specify the LDAP server for my network?

Thanks,
Novice

I read over a LDAP tutorial on constructing LDAP strings.

Thanks anyway,
Novice
 
N

Novice

Novice said:
A couple of comments:
1. Where did you get the variable "Domain_Slash_Machine" from? Did you mean to use Domain_Slash_User everywhere you wrote Domain_Slash_Machine?
2. Is that Visual Basic, C# or just pseudo-code (i.e. the "string" class with a lower case "s", etc) ?

Thanks,
Novice

----- Steve C. Orr [MVP, MCSD] wrote: -----

Try this code. (also set <identity impersonate="true"/> in your web.config)

string Domain_Slash_User = Context.User.Identity.Name;
Domain_Slash_Machine = Domain_Slash_Machine.Replace(@"\",
@"/");
string queryString = @"WinNT://" + Domain_Slash_Machine;

DirectoryEntry obDirEntry = new DirectoryEntry
(queryString);
System.DirectoryServices.PropertyCollection coll =
obDirEntry.Properties;

object obVal = coll["FullName"].Value;
_User = obVal.ToString();

Session.Add("UserFullName", _User);

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Novice said:
Hi all, I'm trying to display the full name of a windows user (not
their login name) using System.DiretoryServices.
Exception Details: System.Runtime.InteropServices.COMException: The
network path was not found
myUserName. But in my source code they are the actual domain and user
name that I use to log into my machine.
machine's domain name, a different error message appears:
Exception Details: System.Runtime.InteropServices.COMException: The
group name could not be found
<%@ Assembly name="System.DirectoryServices, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>><%@ Import Namespace="System.DirectoryServices" %>>> Then I have the following function:
Private Function GetUserName() as String
Dim FullName as string
Dim objUser as new DirectoryEntry
objUser.Path = "WinNT://myDomain/myUserName"
FullName = ObjUser.Name
Return FullName
End Function
Novice

I got it working - no worries.

Thanks anyway,
Novice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top