FormsAuthenticationModule クラス
アセンブリ: System.Web (system.web.dll 内)


アプリケーションの構成ファイルの authentication 要素 (ASP.NET 設定スキーマ) 要素で認証 Mode が Forms に設定されている場合、FormsAuthenticationModule は、HttpContext.User プロパティを、現在の要求に対するユーザー ID を表す IPrincipal オブジェクトに設定します。
FormsAuthenticationModule は Authenticate イベントを公開します。このイベントにより、現在の HttpContext の User プロパティにカスタム IPrincipal オブジェクトを設定できます。Authenticate イベントには、ASP.NET アプリケーションの Global.asax ファイルに、FormsAuthentication_OnAuthenticate というサブルーチンを指定することによってアクセスします。

FormsAuthentication_OnAuthenticate イベントを使用して、現在の HttpContext の User プロパティにカスタム IPrincipal オブジェクトを設定するコード例を次に示します。
Public Sub FormsAuthentication_OnAuthenticate(sender As Object, _ args As FormsAuthenticationEventArgs) If FormsAuthentication.CookiesSupported Then If Not Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing Then Try Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt( _ Request.Cookies(FormsAuthentication.FormsCookieName).Value) args.User = New System.Security.Principal.GenericPrincipal( _ New Samples.AspNet.Security.MyFormsIdentity(ticket), _ New String(0) {}) Catch e As HttpException ' Decrypt method failed. End Try End If Else Throw New Exception("Cookieless Forms Authentication is not " & _ "supported for this application.") End If End Sub
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args) { if (FormsAuthentication.CookiesSupported) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt( Request.Cookies[FormsAuthentication.FormsCookieName].Value); args.User = new System.Security.Principal.GenericPrincipal( new Samples.AspNet.Security.MyFormsIdentity(ticket) , new string[0]); } catch (Exception e) { // Decrypt method failed. } } } else { throw new HttpException("Cookieless Forms Authentication is not " + "supported for this application."); } }


System.Web.Security.FormsAuthenticationModule


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- FormsAuthenticationModule クラスのページへのリンク