AuthenticationService 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
作為網路服務,允許存取 ASP.NET 表單認證。
public ref class AuthenticationService
[System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode=System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Required)]
[System.ServiceModel.ServiceBehavior(ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Multiple, InstanceContextMode=System.ServiceModel.InstanceContextMode.Single, Namespace="http://asp.net/ApplicationServices/v200")]
[System.ServiceModel.ServiceContract(Namespace="http://asp.net/ApplicationServices/v200")]
public class AuthenticationService
[<System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode=System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Required)>]
[<System.ServiceModel.ServiceBehavior(ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Multiple, InstanceContextMode=System.ServiceModel.InstanceContextMode.Single, Namespace="http://asp.net/ApplicationServices/v200")>]
[<System.ServiceModel.ServiceContract(Namespace="http://asp.net/ApplicationServices/v200")>]
type AuthenticationService = class
Public Class AuthenticationService
- 繼承
-
AuthenticationService
- 屬性
備註
AuthenticationService 物件允許您透過 Windows Communication Foundation(WCF)服務來驗證使用者。 當你必須透過 ASP.NET 成員身份,從儲存使用者憑證的網頁應用程式以外的應用程式來驗證使用者時,你會使用 WCF 認證服務。 應用程式必須能夠以 SOAP 格式發送並使用訊息。 透過這個 AuthenticationService 類別,你可以登入、登出使用者、驗證憑證、檢查認證狀態、自訂認證,以及設定認證 Cookie。
該AuthenticationService類別包含四個方法,你只能透過 WCF 服務IsLoggedIn存取:、、 LoginLogoutValidateUser 和 方法。 要呼叫這些方法,你需要在網頁伺服器上啟用認證服務,然後將相容於 WCF 的用戶端應用程式連接到網路服務。 關於如何配置認證服務的資訊,請參閱 如何:啟用 WCF 認證服務。
登入使用者時,你要把使用者憑證傳給該 Login 方法。 如果憑證有效,該 AuthenticationService 類別會建立一個認證 Cookie。 如果認證 cookie 尚未過期,你就知道使用者的憑證已被驗證,無需重新驗證憑證。 (該類別無法提供 AuthenticationService 無 Cookie 驗證功能。)
可以 AuthenticationService 引發兩個事件: Authenticating 和 CreatingCookie。 Authenticating該事件發生在使用者憑證被驗證時。 建立事件處理程式, Authenticating 以自訂使用者憑證的驗證方式。 CreatingCookie當驗證 Cookie 在使用者憑證驗證後設定時,事件會發生。 為事件建立一個事件處理程序 CreatingCookie ,以自訂認證 Cookie。
此 ValidateUser 方法會檢查使用者憑證以進行認證,但不會回傳認證單。 當使用者先前登入過,並且必須在新應用程式會話開始時確認憑證仍然有效時使用 ValidateUser 。
關於從主控台應用程式使用 WCF 認證服務的範例,請參見 Walkthrough: Using ASP.NET Application Services。
建構函式
| 名稱 | Description |
|---|---|
| AuthenticationService() |
初始化 AuthenticationService 類別的新執行個體。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsLoggedIn() |
判斷目前使用者是否已認證。 |
| Login(String, String, String, Boolean) |
檢查使用者憑證,若憑證有效,會建立認證單(Cookie)。 |
| Logout() |
清除瀏覽器中的驗證單(cookie)。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
| ValidateUser(String, String, String) |
在不發出認證票的情況下驗證使用者憑證。 |
事件
| 名稱 | Description |
|---|---|
| Authenticating |
當使用者憑證被驗證時會發生。 |
| CreatingCookie |
當認證 Cookie 正在設定時會發生。 |