AuthenticatingEventArgs 類別

定義

提供 Authenticating 事件的資料。

public ref class AuthenticatingEventArgs : EventArgs
public class AuthenticatingEventArgs : EventArgs
type AuthenticatingEventArgs = class
    inherit EventArgs
Public Class AuthenticatingEventArgs
Inherits EventArgs
繼承
AuthenticatingEventArgs

範例

下列範例顯示事件處理常式,會將 和 Password 值傳遞 UserName 至自訂成員資格提供者,以驗證使用者認證。 事件處理常式會將 設定 Authenticated 為 方法的傳回值, ValidateUser 並將 設定 AuthenticationIsCompletetrueAuthenticationService 讓 類別不會驗證認證。

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 。 類別 AuthenticatingEventArgs 會將值提供給任何 Authenticating 事件處理常式。 藉由使用此類別中可用的屬性,您可以擷取使用者認證來自訂驗證。

類別 AuthenticationService 會在 Authenticating 驗證使用者認證之前引發 事件。 類別 AuthenticationService 會建構 物件的實例, AuthenticatingEventArgs 並將它傳遞至任何 Authenticating 事件處理常式。

您可以使用 UserNamePasswordCustomCredential 屬性來擷取使用者認證。 屬性 CustomCredential 可以包含驗證所需的其他值,例如識別碼。

屬性 Authenticated 會指出使用者認證是否有效。 您可以將 屬性設定 Authenticated 為自訂驗證的結果。 此外,如果您已檢查使用者認證,而且不想讓 AuthenticationService 類別透過預設成員資格提供者檢查使用者認證,請將 屬性 true 設定 AuthenticationIsComplete 為 。

屬性

Authenticated

取得或設定值,表示使用者認證是否有效。

AuthenticationIsComplete

取得或設定值,表示使用者認證已驗證。

CustomCredential

取得額外的使用者值進行驗證。

Password

取得使用者的密碼。

UserName

取得使用者的驗證名稱。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱