C# 通过多个ou组进行Active Directory身份验证
我正在尝试在min obv上遍历我们的ldap路径不想共享实时详细信息,但这里有一些代码,我想我可能必须循环我们的ou组,因为它们位于不同的文件夹中。当我查看节点时,你知道我将如何使用我已经创建的以下代码循环ou组吗C# 通过多个ou组进行Active Directory身份验证,c#,active-directory,ldap,C#,Active Directory,Ldap,我正在尝试在min obv上遍历我们的ldap路径不想共享实时详细信息,但这里有一些代码,我想我可能必须循环我们的ou组,因为它们位于不同的文件夹中。当我查看节点时,你知道我将如何使用我已经创建的以下代码循环ou组吗 string logintype = rbAuthenticationType.SelectedItem.Value.ToString(); if (logintype == "Domain") { string adPath = "LDAP://ipaddress/
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;
}
}