FormsAuthentication 類別
提供驗證服務實作,該實作會使用從網域服務產生的 DomainContext 來執行表單驗證,該網域服務則會實作 IAuthentication 介面。
命名空間: System.ServiceModel.DomainServices.Client.ApplicationServices
組件: System.ServiceModel.DomainServices.Client.Web (於 system.servicemodel.domainservices.client.web.dll)
使用方式
'用途
Dim instance As FormsAuthentication
語法
'宣告
Public Class FormsAuthentication
Inherits WebAuthenticationService
public class FormsAuthentication : WebAuthenticationService
public ref class FormsAuthentication : public WebAuthenticationService
public class FormsAuthentication extends WebAuthenticationService
public class FormsAuthentication extends WebAuthenticationService
備註
若要設定應用程式使用表單驗證,您必須在伺服器和用戶端專案中設定值。當您在用戶端專案中設定值時,您會使用 FormsAuthentication 類別。
在伺服器專案的 Web.config 檔案中,將 authentication mode 設定為 “Forms”
,如下列範例所示。
<system.web>
<authentication mode="Forms"></authentication>
</system.web>
在用戶端應用程式之 Application 物件的建構函式中,將 WebContext 物件的 Authentication 屬性設定為 FormsAuthentication,如下列範例所示。此建構函式通常會在名為 App.xaml.cs 或 App.xaml.vb 的檔案中。
Public Sub New()
InitializeComponent()
Dim webcontext As New WebContext
webcontext.Authentication = New System.ServiceModel.DomainServices.Client.ApplicationServices.FormsAuthentication
Me.ApplicationLifetimeObjects.Add(webcontext)
End Sub
public App()
{
this.Startup += this.Application_Startup;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
WebContext webcontext = new WebContext();
webcontext.Authentication = new System.ServiceModel.DomainServices.Client.ApplicationServices.FormsAuthentication();
this.ApplicationLifetimeObjects.Add(webcontext);
}
繼承階層
System.Object
System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationService
System.ServiceModel.DomainServices.Client.ApplicationServices.WebAuthenticationService
System.ServiceModel.DomainServices.Client.ApplicationServices.FormsAuthentication
執行緒安全性
任何這個類型的公用靜態 (在 Visual Basic 中為 共用) 成員都具備執行緒安全。 不保證任何執行個體成員安全執行緒。
平台
開發平台
Windows XP Home Edition, Windows XP Professional, Windows Server 2003 、Windows Server 2008 和 Windows 2000
目標平台
Change History
另請參閱
參考
FormsAuthentication 成員
System.ServiceModel.DomainServices.Client.ApplicationServices 命名空間