AuthenticationService.Login(String, String, String, Boolean) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
檢查使用者認證,如果認證有效,則建立驗證票證 (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
除了 username
和 password
以外要驗證的值 (如果有的話)。
- isPersistent
- Boolean
值,表示驗證票證在工作階段之間是否仍有效。
傳回
如果使用者認證有效則為 true
,否則為 false
。
- 屬性
例外狀況
userName
或 password
為 null
。
備註
方法 Login 會透過成員資格提供者驗證用戶認證。 您可以使用預設成員資格提供者,或在運行時間指定自定義成員資格提供者。 類別會將 和 傳遞至成員資格提供者ValidateUser的 方法,但不會傳遞 customCredential
。userName
password
AuthenticationService 如果 傳 ValidateUser 回 true
, AuthenticationService 則會建立驗證票證作為 Cookie。 將 isPersistent
參數設定為 true
,以建立上次超過目前會話的驗證票證。
注意
請一律使用驗證服務與安全套接字層 (SSL,方法是使用 HTTPS) 來保護敏感數據。
方法 Login 會 Authenticating 引發事件和 CreatingCookie 事件。 建立 用來 Authenticating 自定義驗證的事件處理程式,例如檢查 中的 customCredential
值,或透過非預設成員資格提供者驗證認證。 中的 customCredential
值不會由預設成員資格提供者驗證。 若要自定義驗證 Cookie,請建立 的 CreatingCookie事件處理程式。
注意
請勿從在 Web 伺服器上執行的程式代碼呼叫 Login 方法。 您只呼叫 Login 方法做為 WCF 服務的一部分。 如需詳細資訊,請參閱 ASP.NET 驗證。