簡體   English   中英

對Active Directory進行ASP.NET用戶身份驗證時遇到問題

[英]Trouble Authenticating ASP.NET Users Against Active Directory

我用“演示”替換了我們的域名...請忽略下圖中的逗號。

我的問題如下:

我想在我的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

這是我們連接到廣告的方式,並且效果很好:

<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);
                }
            }

這是您可以嘗試的方法..您還確定您的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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM