CreateUserWizard.OnCreatingUser メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim e As LoginCancelEventArgs Me.OnCreatingUser(e)

OnCreatingUser メソッドを使用して、MembershipProvider プロパティで指定したメンバシップ プロバイダの CreateUser メソッドに新規ユーザー情報を送信する前に必要な処理を実行します。たとえば、ユーザー アカウントの作成を許可する前に、ユーザー名フィールドをすべて小文字に設定したり、電子メール アドレスを制限されたアドレスの一覧と比較したりできます。
新しいユーザー アカウントの作成要求をキャンセルする必要がある場合は、e パラメータとして渡された LoginCancelEventArgs オブジェクトの Cancel プロパティを true に設定します。
イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの処理と発生」を参照してください。
OnCreatingUser メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnCreatingUser をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnCreatingUser メソッドを必ず呼び出してください。
OnCreatingUser メソッドを使用するカスタム CreateUserWizard コントロールを定義して、UserName プロパティをすべて小文字にするコード例を次に示します。
Imports System Imports System.Web Imports System.Web.UI.WebControls Imports System.Security.Permissions Namespace Samples.AspNet.VB.Controls <AspNetHostingPermission(System.Security.Permissions.SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Class CustomCreateUserWizard Inherits CreateUserWizard Overloads Sub OnCreatingUser(ByVal e As LoginCancelEventArgs) Me.UserName.ToLower() MyBase.OnCreatingUser(e) End Sub End Class End Namespace
using System; using System.Web; using System.Web.UI.WebControls; using System.Security.Permissions; namespace Samples.AspNet.CS.Controls { [AspNetHostingPermission(System.Security.Permissions.SecurityAction.Demand,Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand,Level = AspNetHostingPermissionLevel.Minimal)] public class CustomCreateUserWizard : CreateUserWizard { protected override void OnCreatingUser(LoginCancelEventArgs e) { this.UserName.ToLower(); base.OnCreatingUser(e); } } }
CustomCreateUserWizard を使用した Web ページのデモを行うコード例を次に示します。
<%@ Page Language="VB"%> <%@ Import namespace="Samples.AspNet.VB.Controls" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim createUser As New CustomCreateUserWizard Placeholder1.Controls.Add(createUser) End Sub </script> <html> <head runat="server"> <title>CreateUserWizard.OnCreatingUser sample</title> </head> <body> <form id="form1" runat="server"> <div> <asp:placeholder id="Placeholder1" runat="server"> </asp:placeholder> </div> </form> </body> </html>
<%@ Page Language="C#"%> <%@ Import namespace="Samples.AspNet.CS.Controls" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { CustomCreateUserWizard createUser = new CustomCreateUserWizard(); Placeholder1.Controls.Add(createUser); } </script> <html> <head id="Head1" runat="server"> <title>CreateUserWizard.OnCreatingUser sample</title> </head> <body> <form id="form1" runat="server"> <div> <asp:placeholder id="Placeholder1" runat="server"> </asp:placeholder> </div> </form> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CreateUserWizard.OnCreatingUser メソッドのページへのリンク