1

我用“demo”替换了我们的域名...请忽略下图中缺少的逗号等。

我的问题如下:

我想在我的 ASP.NET Web 应用程序中验证 SBSUsers。我无法弄清楚我的活动目录路径需要什么才能让它工作......

当我将其设置如下时,它无法进行身份验证(我假设因为我的用户不在该路径下)......但它没有给我一个错误:

string adPath = "LDAP://ac-dc01.demo.local:389/CN=Configuration,DC=demo,DC=local";
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(adPath, domainAndUsername, pwd);
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
    return false;
}
// Update the new path to the user in the directory
adPath = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];

当我将它设置为我认为应该的值时,它在 entry.NativeObject 行上出错。

string adPath = "ldap://ac-dc01.demo.local:389/OU=SBSUsers,OU=Users,OU=MyBusiness,DC=demo,DC=local";

有任何想法吗?我是否需要以某种方式打开它以进行“全局”访问?如果是这样,我将如何去做?

LDAP

我能够使用另一款软件成功连接...

LDAP

4

2 回答 2

1

这就是我们连接到 AD 的方式,并且效果很好:

<yourConfig>LDAP://ADServerName/OU=GROUPNAME,DC=domainName,DC=com</YourConfig>

以下是有关如何验证用户的示例代码:

using (PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain,
                                                            ENTER YOUR DOMAIN NAME,
                                                            This is where the config that I mentioned above comes in,
                                                            ContextOptions.Negotiate,
                                                            ENTER YOUR AD SERVICE NAME,
                                                            ENTER YOUR AD PASSWORD))
            {
                UserPrincipal oUser = UserPrincipal.FindByIdentity(oPrincipalContext, THE USERNAME THAT YOU WANT TO VALIDATE);
                if (oUser != null)
                {
                    oADAcct = new CUserADAcct();
                    oADAcct.dumpAcctAttrs(oUser);
                }
            }
于 2013-03-15T19:11:03.587 回答
1

这就是你可以尝试的。你确定你的 DC=Demo 和 DC=Local 对我来说看起来像 OU

const string Domain = "ServerAddress:389";
const string constrParts = @"OU=Users,DC=domain,DC=com";
const string Username = @"someusername";
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain, constrParts);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext,  username);
于 2013-03-15T19:12:51.233 回答