TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

C#操作AD域之测试域连接

Laughing博主
2017-06-30
/
1 评论
/
1,423 阅读
/
98 个字
/
百度已收录
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;  
    }  
}
.Net
朗读
赞(1)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/java/csharp-test-ad-connect.html(转载时请注明本文出处及文章链接)

评论 (1)
  1. 1 闲逛
    Windows 10 · Google Chrome

    呵呵

    2019-04-26 回复
  2. 菏泽 闲逛
    Windows 7 · Google Chrome

    博客大好,让人忘不了!

    2017-12-28 回复
  3. qinnek 闲逛
    Windows 10 · Google Chrome

    感谢分享

    2017-08-01 回复