Active Directory searches

S

Stephan Bour

Hi,
I am trying to authenticate form users using a local Active Directory server
and I get the following error message at compile:

Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'
Source Error:

mName = res.Properties["Name"][0];
mLocation = res.Properties["streetaddress"][0];
mUserID = res.Properties["samaccountname"][0];
mTelephone = res.Properties["telephonenumber"][0];
mEmail = res.Properties["mail"][0];

Any idea what I'm doing wrong?

Thanks for your help,
Stephan.

Here is the whole code block:

public class ADCredentials {
private String mName;
private String mEmail;
private String mLocation;
private String mUserID;
private String mTelephone;

public ADCredentials (String UserID) {
DirectoryEntry de = new
DirectoryEntry("LDAP://NIAID-DC14/CN=Users,DC=NIAID,DC=NIH,DC=GOV","name",
"pass");
DirectorySearcher ds = new
DirectorySearcher("(&(objectCategory=Person)(objectClass=user)(samaccountnam
e=" + UserID + "))");
//Point the Root search to the previous directory entry.
ds.SearchRoot = de;
//Narrow the search scope to current subtree.
ds.SearchScope = SearchScope.Subtree;
SearchResult res = ds.FindOne();
mName = res.Properties["Name"][0];
mLocation = res.Properties["streetaddress"][0];
mUserID = res.Properties["samaccountname"][0];
mTelephone = res.Properties["telephonenumber"][0];
mEmail = res.Properties["mail"][0];
}

public String Name {
get {
return mName;
}
}

public String Email {
get {
return mEmail;
}
}

public String Location {
get {
return mLocation;
}
}

public String UserID {
get {
return mUserID;
}
}

public String Telephone {
get {
return mTelephone;
}
}
}
 
C

Chee Seong Ong

The following loop should help you get what you need.

foreach (string sPropName in srResults.Properties.PropertyNames)
{
if (sNameValue == sPropName)
{
foreach (string sValue in srResults.Properties[sPropName])
{
sRetValue = sValue;
}
}
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top