"index out of range ..." error when querying AD

E

E. Kwong

I have a simple login form to authenticate users. A code segment looks like
this:

search.PropertiesToLoad.Add("cn");

search.PropertiesToLoad.Add("name");

search.PropertiesToLoad.Add("givenname");

search.PropertiesToLoad.Add("sn");

search.PropertiesToLoad.Add("mail");



SearchResult result = search.FindOne();

string fullname = (string)result.Properties["name"][0];

string uname = (string)result.Properties["cn"][0];

string firstname = (string)result.Properties["givenname"][0];

string lastname = (string)result.Properties["sn"][0];

string mmail = (string)result.Properties["mail"][0];





When I tested with several user accounts, some authenticated perfectly fine,
some threw the exception "Index was out of range. Must be non-negative and
less than the size of the collection. Parameter name: index" . The
exception was eventually traced to the " string mmail =
(string)result.Properties["mail"][0]; " statement. So is this because that
user has no email in AD? How best to handle this?



Am a newbie in this area. Any insight appreciate.
 
G

Guest

I have a simple login form to authenticate users. A code segment looks like
this:

search.PropertiesToLoad.Add("cn");

search.PropertiesToLoad.Add("name");

search.PropertiesToLoad.Add("givenname");

search.PropertiesToLoad.Add("sn");

search.PropertiesToLoad.Add("mail");

SearchResult result = search.FindOne();

string fullname = (string)result.Properties["name"][0];

string uname = (string)result.Properties["cn"][0];

string firstname = (string)result.Properties["givenname"][0];

string lastname = (string)result.Properties["sn"][0];

string mmail = (string)result.Properties["mail"][0];

When I tested with several user accounts, some authenticated perfectly fine,
some threw the exception "Index was out of range. Must be non-negative and
less than the size of the collection. Parameter name: index" . The
exception was eventually traced to the " string mmail =
(string)result.Properties["mail"][0]; " statement. So is this because that
user has no email in AD? How best to handle this?

Am a newbie in this area. Any insight appreciate.

http://groups.google.com/group/micr...read/thread/39d7de4f551ca156/76de752c8f2ce6fd
 

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
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top