Login.OnAuthenticate メソッド
アセンブリ: System.Web (system.web.dll 内)
![構文](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![解説](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
OnAuthenticate メソッドは Authenticate イベントを発生させます。Authenticate イベントを使用して、カスタム認証方式を実装します。
イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの発生」を参照してください。
OnAuthenticate メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnAuthenticate をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnAuthenticate メソッドを呼び出してください。![使用例](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
Authenticate イベントを使用して、サイト固有のカスタム認証コードを呼び出すコード例を次に示します。
<%@ page language="VB" %> <script runat="server"> ' This custom login control overloads the OnAuthenticate method ' to call a site-specific authentication method. Class CustomLogin Inherits Login Private Function SiteSpecificAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean ' Insert code that implements a site-specific custom ' authentication method here. ' ' This example implementation always returns false. Return False End Function Overloads Sub OnAuthenticate(ByVal e As AuthenticateEventArgs) Dim Authenticated As Boolean Authenticated = SiteSpecificAuthenticationMethod(UserName, Password) e.Authenticated = Authenticated End Sub End Class ' Add the custom login control to the page. Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim loginControl As New CustomLogin loginControl.ID = "loginControl" PlaceHolder1.Controls.Add(loginControl) End Sub </script> <html> <body> <form runat="server"> <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder> </form> </body> </html>
<%@ page language="C#"%> <script runat="server"> // This custom login control overloads the OnAuthenticate method // to call a site-specific authentication method. class CustomLogin : Login { private bool SiteSpecificAuthenticationMethod(string UserName, string Password) { // Insert code that implements a site-specific custom // authentication method here. // // This example implementation always returns false. return false; } override protected void OnAuthenticate(AuthenticateEventArgs e) { bool Authenticated = false; Authenticated = SiteSpecificAuthenticationMethod(UserName, Password); e.Authenticated = Authenticated; } } // Add the custom login control to the page. void Page_Load(object sender, EventArgs e) { CustomLogin loginControl = new CustomLogin(); loginControl.ID = "loginControl"; Placeholder1.Controls.Add(loginControl); } </script> <html> <body> <form runat="server"> <asp:placeholder id="Placeholder1" runat="server"></asp:placeholder> </form> </body> </html>
![プラットフォーム](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
![バージョン情報](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
- Login.OnAuthenticate メソッドのページへのリンク