Login.OnLoggingIn メソッドとは? わかりやすく解説

Login.OnLoggingIn メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

認証が行われる前にユーザーログイン情報送信したときに、LoggingIn イベント発生させます

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Overridable Sub
 OnLoggingIn ( _
    e As LoginCancelEventArgs _
)
Dim e As LoginCancelEventArgs

Me.OnLoggingIn(e)
protected virtual void OnLoggingIn (
    LoginCancelEventArgs e
)
protected:
virtual void OnLoggingIn (
    LoginCancelEventArgs^ e
)
protected void OnLoggingIn (
    LoginCancelEventArgs e
)
protected function OnLoggingIn (
    e : LoginCancelEventArgs
)

パラメータ

e

イベント データ格納している LoginCancelEventArgs。

解説解説
使用例使用例

LoggingIn イベント使用してユーザーUserName プロパティ整形式電子メール アドレス入力するようにするコード例次に示します整形式アドレス入力されなかった場合LoggingIn イベント ハンドラログイン試行キャンセルし、InstructionText プロパティ指定されエラー メッセージ表示します

<%@ page language="VB" %>

<script runat="server">
    ' This custom Login control checks the user name
    ' entered by the user is a valid e-mail address.
    Class CustomLogin
        Inherits Login
        
        Function IsValidEmail(ByVal strIn As
 String) As Boolean
            ' Return true if strIn is in valid e-mail format.
            Return Regex.IsMatch(strIn, ("^([\w-\.]+)@((\[[0-9]{1
,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
        End Function

        Overrides Protected Sub
 OnLoggingIn(ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
            If Not IsValidEmail(UserName) Then
                InstructionText = "You must enter a valid e-mail
 address."
                e.Cancel = True
            Else
                InstructionText = String.Empty
            End If
        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 id="Form1" runat="server">
    <asp:placeholder id="Placeholder1" runat="Server"></asp:placeholder>
</form>
</body>
</html>
<%@ page language="C#" %>

<script runat="server">
// This custom Login control checks the user name 
// entered by the user is a valid e-mail address
class CustomLogin : Login
{
    bool IsValidEmail(string strIn)
    {
        // Return true if strIn is in valid e-mail format.
        return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
 
    }

    override protected void OnLoggingIn(System.Web.UI.WebControls.LoginCancelEventArgs
 e)
    {
        if (!IsValidEmail(UserName)) 
        {
            InstructionText = "You must enter a valid e-mail address.";
            e.Cancel = true;
        }
        else 
        {
            InstructionText = String.Empty;
        }
    }
}

    // 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 id="Form1" runat="server">
            <asp:placeholder id="Placeholder1" runat="server"></asp:placeholder>
        </form>
    </body>
</html>

Login コントロール拡張する方法次のコード例示しますCustomLogin コントロールには、認証使用するメンバシップ プロバイダユーザー選択できる DropDownList コントロール含まれています(これらのプロバイダは、Web.config で設定されます)。OnLoggingIn メソッドで、MembershipProvider プロパティDropDownList コントロール選択された値に設定されます。

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Namespace Samples.AspNet.Controls

    NotInheritable Public Class
 CustomLogin
        Inherits Login

        Public Sub New()
 
        End Sub 'New

        Protected Overrides Sub
 OnLoggingIn(ByVal e As LoginCancelEventArgs)
 

            ' Set the Membership provider for the Login control from
 a DropDownList.
            Dim list As DropDownList = CType(Me.FindControl("domain"),
 DropDownList)
            Me.MembershipProvider = list.SelectedValue
            MyBase.OnLoggingIn(e)

        End Sub 'OnLoggingIn


        Protected Overrides Sub
 CreateChildControls() 

            LayoutTemplate = New MyTemplate()
            MyBase.CreateChildControls()

        End Sub 'CreateChildControls
    End Class 'CustomLogin

    ' A Template that contains the child controls.
    Public Class MyTemplate
        Implements ITemplate

        Sub InstantiateIn(ByVal container As
 Control)  Implements ITemplate.InstantiateIn
            ' A TextBox for the user name.
            Dim username As New
 TextBox()
            username.ID = "username"

            ' A TextBox for the password.
            Dim password As New
 TextBox()
            password.ID = "password"

            ' A CheckBox to remember the user on subsequent visits.
            Dim remember As New
 CheckBox()
            remember.ID = "RememberMe"
            remember.Text = "Don't forget me!"

            ' Failure Text.
            Dim failure As New
 Literal()
            failure.ID = "FailureText"

            ' A DropDownList to choose the Membership provider.
            Dim domain As New
 DropDownList()
            domain.ID = "Domain"
            domain.Items.Add(New ListItem("SqlMembers"))
            domain.Items.Add(New ListItem("SqlMembers2"))

            ' A Button to log in.
            Dim submit As New
 Button()
            submit.CommandName = "login"
            submit.Text = "LOGIN"

            container.Controls.Add(New LiteralControl("UserName:"))
            container.Controls.Add(username)
            container.Controls.Add(New LiteralControl("<br>Password:"))
            container.Controls.Add(password)
            container.Controls.Add(New LiteralControl("<br>"))
            container.Controls.Add(remember)
            container.Controls.Add(New LiteralControl("<br>Domain:"))
            container.Controls.Add(domain)
            container.Controls.Add(New LiteralControl("<br>"))
            container.Controls.Add(failure)
            container.Controls.Add(New LiteralControl("<br>"))
            container.Controls.Add(submit)

        End Sub 'ITemplate.InstantiateIn
    End Class 'MyTemplate
End Namespace
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.Controls
{
    public sealed class CustomLogin : Login
    {
        public CustomLogin() { }
        
        protected override void OnLoggingIn(LoginCancelEventArgs
 e)
        {
            // Set the Membership provider for the Login control from
 a DropDownList.
            DropDownList list = (DropDownList)this.FindControl("domain");
            this.MembershipProvider = list.SelectedValue;
            base.OnLoggingIn(e);
        }
        
        protected override void CreateChildControls()
        {
            LayoutTemplate = new MyTemplate();
            base.CreateChildControls();
        }
    }
    
    // A Template that contains the child controls.
    public class MyTemplate : ITemplate
    {
        void ITemplate.InstantiateIn(Control container)
        {
            // A TextBox for the user name.
            TextBox username = new TextBox();
            username.ID = "username";
            
            // A TextBox for the password.
            TextBox password = new TextBox();
            password.ID = "password";
            
            // A CheckBox to remember the user on subsequent visits.
            CheckBox remember = new CheckBox();
            remember.ID = "RememberMe";
            remember.Text = "Don't forget me!";
            
            // Failure Text.
            Literal failure = new Literal();
            failure.ID = "FailureText";
            
            // A DropDownList to choose the Membership provider.
            DropDownList domain = new DropDownList();
            domain.ID = "Domain";
            domain.Items.Add(new ListItem("SqlMembers"));
            domain.Items.Add(new ListItem("SqlMembers2"));
            
            // A Button to log in.
            Button submit = new Button();
            submit.CommandName = "login";
            submit.Text = "LOGIN";

            container.Controls.Add(new LiteralControl("UserName:"));
            container.Controls.Add(username);
            container.Controls.Add(new LiteralControl("<br>Password:"));
            container.Controls.Add(password);
            container.Controls.Add(new LiteralControl("<br>"));
            container.Controls.Add(remember);
            container.Controls.Add(new LiteralControl("<br>Domain:"));
            container.Controls.Add(domain);
            container.Controls.Add(new LiteralControl("<br>"));
            container.Controls.Add(failure);
            container.Controls.Add(new LiteralControl("<br>"));
            container.Controls.Add(submit);
        }
    }    
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Login.OnLoggingIn メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Login.OnLoggingIn メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS