AuthenticatingEventArgs.Authenticated 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,表示使用者認證是否有效。
public:
property bool Authenticated { bool get(); void set(bool value); };
public bool Authenticated { get; set; }
member this.Authenticated : bool with get, set
Public Property Authenticated As Boolean
屬性值
如果使用者認證有效則為 true
,否則為 false
。
範例
下列範例顯示事件處理常式,會將 和 Password 值傳遞 UserName 至自訂成員資格提供者,以驗證使用者認證。 事件處理常式會將 設定 Authenticated 為 方法的傳回值, ValidateUser 並將 設定 AuthenticationIsComplete 為 true
, AuthenticationService 讓 類別不會驗證認證。
void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
{
if (e.UserName.IndexOf("@contoso.com") >= 0)
{
e.Authenticated = Membership.Providers["ContosoSqlProvider"].ValidateUser(e.UserName, e.Password);
}
else if (e.UserName.IndexOf("@fabrikam.com") >= 0)
{
e.Authenticated = Membership.Providers["FabrikamSqlProvider"].ValidateUser(e.UserName, e.Password);
}
else
{
e.Authenticated = Membership.Provider.ValidateUser(e.UserName, e.Password);
}
e.AuthenticationIsComplete = true;
}
Sub AuthenticationService_Authenticating _
(ByVal sender As Object, _
ByVal e As System.Web.ApplicationServices.AuthenticatingEventArgs)
If (e.Username.IndexOf("@contoso.com") >= 0) Then
e.Authenticated = Membership.Providers("ContosoSqlProvider").ValidateUser(e.Username, e.Password)
ElseIf (e.Username.IndexOf("@fabrikam.com") >= 0) Then
e.Authenticated = Membership.Providers("FabrikamSqlProvider").ValidateUser(e.Username, e.Password)
Else
e.Authenticated = Membership.Provider.ValidateUser(e.Username, e.Password)
End If
e.AuthenticationIsComplete = True
End Sub
備註
如果您在事件的事件處理常式 Authenticating 中驗證使用者認證,請設定 Authenticated 屬性以指出使用者認證是否有效。 如果使用者認證有效,而且不需要額外的驗證,請將 設定 Authenticated 為 true
和 AuthenticationIsCompletetrue
。 您可以設定 AuthenticationIsComplete 屬性,指出驗證服務應該略過驗證使用者的預設步驟。 只有在 設為 true
時 AuthenticationIsComplete ,類別才會 AuthenticationService 使用 中的 Authenticated 值。 如果 為 AuthenticationIsCompletefalse
,類別會 AuthenticationService 呼叫預設成員資格提供者來驗證使用者認證,然後覆寫 中的 Authenticated 值。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應