Request.ServerVariables("AUTH_USER")??

J

Jim in Arizona

I'm new to aspnet with only limited experience with classic asp. Since
I'm on a domain and all users are authenticated. In the past using
classic asp I used request.servervariables("auth_user") to grab the
domain logon name of the user. Is there a better way or more detailed
way in aspnet? Like, instead of putting "mydomain\bobjones" into a
variable using request.servervariables("auth_user"), can I extract the
actual name "Bob Jones" from Active Directory?

Thanks,
Jim
 
Z

Ziemowit

It said:
I'm new to aspnet with only limited experience with classic asp. Since
I'm on a domain and all users are authenticated. In the past using
classic asp I used request.servervariables("auth_user") to grab the
domain logon name of the user. Is there a better way or more detailed
way in aspnet? Like, instead of putting "mydomain\bobjones" into a
variable using request.servervariables("auth_user"), can I extract the
actual name "Bob Jones" from Active Directory?
Try to using LDAP queries to get all info you need from AD.

Ziemowit
msn:[email protected]
 
Z

Ziemowit

No problem, examples directly from my code with short comments:

public string GetDisplayName(string cn) //cn is unique for user
{
string FullName = "";
try
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://server/DC=yourdomain,DC=com"); //path for
server that store AD, can be domain server
entry.AuthenticationType = AuthenticationTypes.ReadonlyServer; //we
want only readonly access
entry.Username = "username"; //if domain allow anonymous access
to AD application then these two rows are not required
entry.Password = "password"; //if not, then you will need domain
account to acces to AD server
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(cn="+cn+")";
search.PropertiesToLoad.Add("displayName"); //name of property to
load
SearchResult sr = search.FindOne();
if (sr != null)
{
FullName = sr.Properties["displayName"][0].ToString(); //read
property
}
search.Dispose();
entry.Dispose();
}
catch
{
}
return FullName; //thats all
}

You have to check if your application have access to AD server and
create domain account if required. To get info what LDAP paths should
be I suggest you to use LDAPBrowser - cool software for browsing LDAP.

I hope it helps

Ziemowit
 
J

Jim in Arizona

Ziemowit said:
No problem, examples directly from my code with short comments:

public string GetDisplayName(string cn) //cn is unique for user
{
string FullName = "";
try
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://server/DC=yourdomain,DC=com"); //path for
server that store AD, can be domain server
entry.AuthenticationType = AuthenticationTypes.ReadonlyServer; //we
want only readonly access
entry.Username = "username"; //if domain allow anonymous access
to AD application then these two rows are not required
entry.Password = "password"; //if not, then you will need domain
account to acces to AD server
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(cn="+cn+")";
search.PropertiesToLoad.Add("displayName"); //name of property to
load
SearchResult sr = search.FindOne();
if (sr != null)
{
FullName = sr.Properties["displayName"][0].ToString(); //read
property
}
search.Dispose();
entry.Dispose();
}
catch
{
}
return FullName; //thats all
}

You have to check if your application have access to AD server and
create domain account if required. To get info what LDAP paths should
be I suggest you to use LDAPBrowser - cool software for browsing LDAP.

I hope it helps

Ziemowit

I'm a vb user and c# is a bit greek to me but I think I can adapt and
overcome. :)

Yesterday I went through the System.DirectoryServices.ActiveDirectory
namespace in hopes of finding something useful in there for my purposes and
after getting lost of a while, was unable to find anything to suit my
purpose. Oh well.

Thanks for the help. I'll put it to good use.

Jim
 

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

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top