473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Active Directory searches

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)(objec tClass=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;
}
}
}

Nov 17 '05 #1
1 1251
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;
}
}

--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).
--------------------
User-Agent: Microsoft-Entourage/10.1.4.030702.0
Date: Wed, 15 Oct 2003 13:01:35 -0400
Subject: Active Directory searches
From: Stephan Bour <sb***@niaid.nih.gov>
Message-ID: <BBB2F5AF.A02F%sb***@niaid.nih.gov>
Mime-version: 1.0
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 137.187.177.34
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184365
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Hi,
I am trying to authenticate form users using a local Active Directory serverand 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)(obje ctClass=user)(samaccountna me=" + 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;
}
}
}


Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: scoomey | last post by:
Note: I'm cross-posting the below to nyphp.org as well. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I've been struggling with an issue for a few months. I am attempting to search...
3
by: MIchele | last post by:
Hi I want to access via VB.Net the active directory I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users.. Anyone can help me? Please... ...
9
by: Mario Rodriguez | last post by:
Hi people. I have a problem adding users to Win2003 active directory programatically. When I execute my app throws the following exception: .................The specified directory service...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: Tash | last post by:
I am having a weird problem. I am trying to use the following code to query active directory. Function IsExistInAD(ByVal loginName As String) As Boolean Dim userName As String =...
9
by: Patrick | last post by:
I have an ASP.NET page that searches for someone in the corporate Active Directory. It had been working fine until recently when I changed from Basic Authentication on IIS6 back to Integrated...
1
by: Rick | last post by:
Does anybody have any any of the following functions written in VB.NET?: 1) To check if a user exists. 2) to create the user if the user does not exist 3) to check if an OU exists 4) to create...
0
by: Brian Mitchell | last post by:
Is there any way to return active directory objects from the object's guid? My basic problem is that I don't know the appropriate search filters. Does anyone know of any sites that list them? (like...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.