以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  AD域用户验证  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=184954)

--  作者:xunxun0903
--  发布时间:2023/1/19 16:58:00
--  AD域用户验证
private void btnLogin_Click(object sender, EventArgs e)
{
    if( txtUsername.Text.Length == 0 || txtPassword.Text.Length == 0 ) {
        MessageBox.Show("用户名或者密码不能为空。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }

    string ldapPath = "LDAP://" + GetDomainName();
    string domainAndUsername = Environment.UserDomainName + "\\\\" + txtUsername.Text;
    DirectoryEntry entry = new DirectoryEntry(ldapPath, domainAndUsername, txtPassword.Text);

    DirectorySearcher search = new DirectorySearcher(entry);

    try {
        SearchResult result = search.FindOne();

        MessageBox.Show("登录成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    catch( Exception ex ) {
        // 如果用户名或者密码不正确,也会抛出异常。
        MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
    }
}
请问这个在Foxtable中怎么写啊? 用于域验证

--  作者:有点蓝
--  发布时间:2023/1/19 17:14:00
--  
c#转vb:https://converter.telerik.com/


然后添加各种.net类型对应的命名空间,比如DirectoryEntry
1、添加System.DirectoryServices.dll的引用:http://www.foxtable.com/webhelp/topics/1936.htm
2、代码里添加命名空间(具体什么命名空间可以打开vs查看,或者到微软文档搜索:https://learn.microsoft.com/zh-cn/dotnet/api/system.directoryservices.directoryentry?view=netframework-4.0)

dim entry as new System.DirectoryServices.DirectoryEntry(ldapPath, domainAndUsername, txtPassword.Text);