Network login and e-mail address

B

Bruce Wood

I've been mucking about with Environment.UserName and similar
properties in .NET. I can get the user's login name for their machine,
but unfortunately that doesn't get me much for users logged into our
corporate network through laptops: all its gets me is their user ID on
the laptop, which means nothing at the corporate level.

Does anyone know how I can get my hands on the username that was used
to log into Microsoft Networking? This is our corporate user name and
it's what I should be using to stamp record updates, etc.

As well, does anyone know how to get my hands on the user's default
e-mail address, the one that Outlook (et al) uses by default when you
send an e-mail message?
 
V

Vadym Stetsyak

You can use Environment.UserDomainName if the application is WinForms one
and HttpContext.Current.User.Identity.Name if you are in the ASP.NET
application.

Once you've obtained the domain name
System.DirectoryServices namespace will help you. It contains necessary
classess to query Active Directory for the info you need.
It uses LDAP pathes. Outlook Exchange server can also be queried in the same
way.
 
B

Bruce Wood

After a bit more mucking around, I think I've figured out what I need:
I need the user's name in a particular domain.

The domain and domain user name on my laptop are pretty useless. The
important credentials are those with which I log onto the "CORP",
domain: our corporate domain.

If I query Environment.UserName and Environment.UserDomainName, I just
get domain "BRUCE", username "Bruce", which I know isn't right.
However, I also know that I have to login to domain "CORP" in order to
do anything useful on our network.

So, I don't want the _current_ user name and domain. I want whatever
user name was used to log onto domain "CORP". Is there any way to get
that in .NET? I took a tour around System.Security.Principal, but it
made my head hurt. :)
 
V

Vadym Stetsyak

You can look at DirectoryEntry constructor. It takes domain name, login
name, passwd and auth type parameters. After you've obtained the
DirectoryEntry - you have access to all the properties of Active Directory
account
 

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