I have this method that gets me groups from AD:
public ArrayList GetUserGroups(string sUserName)
{
ArrayList myItems = new ArrayList();
UserPrincipal oUserPrincipal = GetUser(sUserName);
PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
foreach (Principal oResult in oPrincipalSearchResult)
{
myItems.Add(oResult.Name);
}
return myItems;
}
But when I go to use it:
protected void AuthenticateAndLoadUserProfile()
{
string username;
string password;
username = Login1.UserName;
password = Login1.Password;
ADAccountManagement adAuth = new ADAccountManagement();
try
{
if (true == adAuth.ValidateCredentials(username, password))
{
// Retrieve the user's groups
string groups = adAuth.GetUserGroups(username);
// Create the authetication ticket
FormsAuthenticationTicket authTicket =
new FormsAuthenticationTicket(1, // version
username,
DateTime.Now,
DateTime.Now.AddMinutes(30),
false, groups);
// Now encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
// Create a cookie and add the encrypted ticket to the
// cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
// Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);
// Redirect the user to the originally requested page
Response.Redirect(FormsAuthentication.GetRedirectUrl(username, false));
}
else
{
Login1.FailureText = "Authentication failed, check username and password.";
}
}
catch (Exception ex)
{
Login1.FailureText = ex.Message;
}
}
It gives me an error of "cannot implicitly convert type 'system.collections.arraylist' to 'string'"
I have tried to change the return of the method to:
return myItems.ToString();
but then a get the reverse error on that: "cannot implicitly convert type 'string' to 'system.collections.arraylist' '"
So I am confused and I do not know what to do. Can someone please help. Thank you.