簡體   English   中英

Active Directory ASP.NET在ASP.NET MVC 3中進行身份驗證

[英]active directory asp.net forms authentication in asp.net mvc 3

我必須實現這樣的接口:

interface IMembershipWrapper
{
  Guid GetUserId();
  Guid GetUserId(string username, bool userIsOnline);
  bool ValidateUser(string userName, string password);
    …
}

針對活動目錄並使用Unity注入它。

對於某些方法,我可能會拋出NotImplementedException異常,但您認為通常可能嗎? 您推薦什么策略?

我知道我可以描述通過在web.config配置“活動目錄asp.net窗體身份驗證” 在這里 不幸的是,這不是一個選擇。

這完全可以實現,而無需在web.config中更改身份驗證系統。 特別是如果您使用的是.NET 3.5+。 看一下System.DirectoryServices.AccountManagement

要實現GetUserId(string username, bool userIsOnline)您可能需要嘗試執行以下操作:

public Guid GetUserId(string username, bool userIsOnline) {
    using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "[active directory domain here]")) {
        var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username);
        if(user != null)
            return user.Guid.Value;
        else
            return null;
    }
}

要實現ValidateUser(string userName, string password) ValidateCredentials() ,請在PrinicalContext上使用ValidateCredentials()

public bool ValidateUser(string userName, string password) {
    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "[active directory domain here]"))
    {
        return pc.ValidateCredentials(userName, password);
    }
}

如果沒有有關您的實現的更多信息,我不確定如何實現GetUserId() ,因為似乎您沒有足夠的信息來訪問Active Directory。

暫無
暫無

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

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