我正试图在min obv遍历我们的ldap路径不想分享实时详细信息但是这里有一些代码我认为我可能需要循环我们的ou组,因为当我查看节点时它们在不同的文件夹中,任何人都知道如何使用我已经创建的下面的代码来循环你们。
string logintype = rbAuthenticationType.SelectedItem.Value.ToString();
if (logintype == "Domain")
{
string adPath = "LDAP://ipaddress/DC=companynamee"; //Path to your LDAP directory server
LdapAuthentication adAuth = new LdapAuthentication(adPath);
try
{
if (true == adAuth.IsAuthenticated(txtDomain.Text, txtUserName.Text, txtPassword.Text))
{
string groups = adAuth.GetGroups();
//Create the ticket, and add the groups.
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
txtUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(60), chkRememberMe.Checked, groups);
//Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//Create a cookie, and then 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);
//You can redirect now.
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text, false));
}
else
{
lblerror.Text = "Authentication did not succeed. Check user name and password.";
}
}
catch (Exception ex)
{
lblerror.Text = "Error authenticating. " + ex.Message;
}
}