Share via


AuthenticationService.Login(String, String, String, Boolean) 方法

定義

檢查使用者認證,如果認證有效,則建立驗證票證 (Cookie)。

public:
 bool Login(System::String ^ username, System::String ^ password, System::String ^ customCredential, bool isPersistent);
[System.ServiceModel.OperationContract]
public bool Login (string username, string password, string customCredential, bool isPersistent);
[<System.ServiceModel.OperationContract>]
member this.Login : string * string * string * bool -> bool
Public Function Login (username As String, password As String, customCredential As String, isPersistent As Boolean) As Boolean

參數

username
String

要驗證的使用者名稱。

password
String

指定之使用者的密碼。

customCredential
String

除了 usernamepassword 以外要驗證的值 (如果有的話)。

isPersistent
Boolean

值,表示驗證票證在工作階段之間是否仍有效。

傳回

如果使用者認證有效則為 true,否則為 false

屬性

例外狀況

userNamepasswordnull

備註

方法 Login 會透過成員資格提供者驗證使用者認證。 您可以使用預設成員資格提供者,或在執行時間指定自訂成員資格提供者。 類別 AuthenticationService 會將 和 password 傳遞 userName 至成員資格提供者的 ValidateUser 方法,但不會傳遞 customCredential 。 如果 ValidateUsertrue 回 , AuthenticationService 則會建立驗證票證作為 Cookie。 將 isPersistent 參數設定為 true ,以建立持續超過目前會話的驗證票證。

注意

一律使用驗證服務與安全通訊端層 (SSL,方法是使用 HTTPS) 來保護敏感性資料。

方法 LoginAuthenticating 引發 事件和 CreatingCookie 事件。 建立 事件處理常式 Authenticating 以自訂驗證,例如檢查 中的 customCredential 值,或透過非預設成員資格提供者驗證認證。 中的 customCredential 值不會由預設成員資格提供者驗證。 若要自訂驗證 Cookie,請建立 的 CreatingCookie 事件處理常式。

注意

請勿從 Web 服務器上執行的程式碼呼叫 Login 方法。 您只會呼叫 Login 方法做為 WCF 服務的一部分。 如需詳細資訊,請參閱 ASP.NET 驗證

適用於

另請參閱