Laughing
C#操作AD域之测试域连接
06/30
本文最后更新于2021年04月27日,已超过1241天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
C#操作域的第一步便是测试程序是否能成功连接到域,通过LDAP协议,可以非常简单的测试域连接的情况。代码如下
/// </summary>
/// <param name="domainName">域名或IP</param>
/// <param name="userName">用户名</param>
/// <param name="userPwd">密码</param>
/// <param name="entry">域</param>
/// <returns></returns>
public string IsConnect(string domainName, string userName, string userPwd, out DirectoryEntry domain)
{
domain = new DirectoryEntry();
try
{
domain.Path = string.Format("LDAP://{0}", domainName);//LDAP是轻量目录访问协议
domain.Username = userName;
domain.Password = userPwd;
domain.AuthenticationType = AuthenticationTypes.Secure;//身份验证的类型
domain.RefreshCache();//将此DirectoryEntry 对象的属性值加载到属性缓存中
return "测试连接成功!";
}
catch (Exception ex)
{
return "[IsConnected方法]错误信息:" + ex.Message;
}
}
版权属于:
香草物语
本文链接:
https://www.xiangcaowuyu.net/java/csharp-test-ad-connect.html(转载时请注明本文出处及文章链接)
作品采用:
呵呵
博客大好,让人忘不了!
感谢分享