AJAX アコーディオンを使用したパスワードのリセットとアカウント作成の制御
AJAX アコーディオンを使用して、ログイン、パスワード回復、パスワード リセット、およびアカウント作成コントロールを組み合わせて作成します。
この記事では、AJAX Toolkit を既にダウンロードしていることを前提としています。ダウンロードしていない場合は、以下のリンクを使用して追加してください。
ログイン、新しいアカウントの作成、パスワードの回復、およびパスワードのリセットを処理するための結合されたページを作成すると、4 つの異なるページを 1 つに結合できることを意味し、私の意見では、サイトがより滑らかになります。
これが機能するためには、次のドキュメントを簡単に確認してください。
開始する前に、ユーザー ストアがデータベースに追加されていることを確認してください。
アコーディオンコントロール
まず、AJAX Toolkit Script Manager と Accordian Control をページに追加し、次のように 4 つのペインを追加します。
HTML
<asp:Accordion ID="Accordion1" runat="server" CssClass="accordion" ContentCssClass="accordionContent" HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected">
<Panes>
<asp:AccordionPane ID="Login" runat="server" CssClass="accordion">
<Header>Login</Header>
<Content>
</Content>
</asp:AccordionPane>
<asp:AccordionPane ID="NewAccount" runat="server">
<Header>New Account</Header>
<Content>
</Content>
</asp:AccordionPane>
<asp:AccordionPane ID="RecoverPassword" runat="server">
<Header>Recover Password</Header>
<Content>
</Content>
</asp:AccordionPane>
<asp:AccordionPane ID="AccordionPane1" runat="server">
<Header>Reset Password</Header>
<Content>
</Content>
</asp:AccordionPane>
</Panes>
</asp:Accordion>
<Panes>
<asp:AccordionPane ID="Login" runat="server" CssClass="accordion">
<Header>Login</Header>
<Content>
</Content>
</asp:AccordionPane>
<asp:AccordionPane ID="NewAccount" runat="server">
<Header>New Account</Header>
<Content>
</Content>
</asp:AccordionPane>
<asp:AccordionPane ID="RecoverPassword" runat="server">
<Header>Recover Password</Header>
<Content>
</Content>
</asp:AccordionPane>
<asp:AccordionPane ID="AccordionPane1" runat="server">
<Header>Reset Password</Header>
<Content>
</Content>
</asp:AccordionPane>
</Panes>
</asp:Accordion>
ログイン コントロール (ページ 1)
これがコントロールの基本です。私は組み込みコントロールのわずかに追加されたバージョンを使用しています。これは、スタイルをボード全体で互いに一致するように設定できることを意味します。まずログイン コントロールです。ログイン ツールボックスからドラッグするか、以下のコードを使用します。独自のものを追加する場合、Visual Basic を調整する必要がある場合があります。
HTML
<asp:Login ID="Login1" runat="server" Width="100%" RememberMeSet="True">
<LayoutTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse; width: 100%;">
<tr>
<td>
<table cellpadding="0" style="width:100%;">
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td style="width: 70%;">
<asp:TextBox ID="UserName" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" style="width: 20%;">Password:</asp:Label>
</td>
<td style="width: 70%;">
<asp:TextBox ID="Password" runat="server" TextMode="Password" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2" align="center" >
<asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="LoginButton" runat="server" Text="Log In" ValidationGroup="Login1" CommandName="Login" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
<LayoutTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse; width: 100%;">
<tr>
<td>
<table cellpadding="0" style="width:100%;">
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td style="width: 70%;">
<asp:TextBox ID="UserName" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" style="width: 20%;">Password:</asp:Label>
</td>
<td style="width: 70%;">
<asp:TextBox ID="Password" runat="server" TextMode="Password" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2" align="center" >
<asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="LoginButton" runat="server" Text="Log In" ValidationGroup="Login1" CommandName="Login" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
ユーザー作成ウィザード (ペイン 2)
次に、Create User Wizard を追加します。ここでも、組み込みのコントロールを使用しましたが、テンプレートを編集して、必要に応じてスタイルを設定しました。以前と同様に、以下のコードを使用するか、独自のコードをドラッグできます。
HTML
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" Width="100%" ContinueDestinationPageUrl="/Home">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse; width: 100%;">
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td style="width: 70%;">
<asp:TextBox ID="UserName" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
</td>
<td>
<asp:TextBox ID="Email" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label>
</td>
<td>
<asp:TextBox ID="Question" runat="server" style="width: 80%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" runat="server"
ControlToValidate="Question" ErrorMessage="Security question is required."
ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label>
</td>
<td>
<asp:TextBox ID="Answer" runat="server" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Security answer is required."
ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="Password" ControlToValidate="ConfirmPassword"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
<CustomNavigationTemplate>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="right" colspan="0" style="text-align: center">
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Create User" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<ContentTemplate>
<table style="font-size:100%;width:100%;">
<tr>
<td style="text-align: center">
Your account has been successfully created. Click continue to go through to personalise your experience.</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="ContinueButton" runat="server" CausesValidation="False" CommandName="Continue" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<FinishNavigationTemplate>
<asp:Button ID="FinishPreviousButton" runat="server" CausesValidation="False"
CommandName="MovePrevious" Text="Previous" />
<asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete"
Text="Finish" />
</FinishNavigationTemplate>
<StartNavigationTemplate>
<asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext"
Text="Next" />
</StartNavigationTemplate>
<StepNavigationTemplate>
<asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False"
CommandName="MovePrevious" Text="Previous" />
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Next" />
</StepNavigationTemplate>
</asp:CreateUserWizard>
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse; width: 100%;">
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td style="width: 70%;">
<asp:TextBox ID="UserName" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
</td>
<td>
<asp:TextBox ID="Email" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label>
</td>
<td>
<asp:TextBox ID="Question" runat="server" style="width: 80%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" runat="server"
ControlToValidate="Question" ErrorMessage="Security question is required."
ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label>
</td>
<td>
<asp:TextBox ID="Answer" runat="server" style="width: 30%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Security answer is required."
ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="Password" ControlToValidate="ConfirmPassword"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
<CustomNavigationTemplate>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="right" colspan="0" style="text-align: center">
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Create User" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<ContentTemplate>
<table style="font-size:100%;width:100%;">
<tr>
<td style="text-align: center">
Your account has been successfully created. Click continue to go through to personalise your experience.</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="ContinueButton" runat="server" CausesValidation="False" CommandName="Continue" Text="Continue" ValidationGroup="CreateUserWizard1" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<FinishNavigationTemplate>
<asp:Button ID="FinishPreviousButton" runat="server" CausesValidation="False"
CommandName="MovePrevious" Text="Previous" />
<asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete"
Text="Finish" />
</FinishNavigationTemplate>
<StartNavigationTemplate>
<asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext"
Text="Next" />
</StartNavigationTemplate>
<StepNavigationTemplate>
<asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False"
CommandName="MovePrevious" Text="Previous" />
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Next" />
</StepNavigationTemplate>
</asp:CreateUserWizard>
パスワードの回復 (ペイン 3)
ここでも、テンプレートを編集した標準コントロールです。このコントロールは、追加のコード ビハインドを使用しない唯一のコントロールです。
HTML
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server" Width="100%">
<QuestionTemplate>
<table cellpadding="0" style="width:100%;">
<tr>
<td align="center" colspan="2">
Identity Confirmation</td>
</tr>
<tr>
<td align="center" colspan="2">
Answer the following question to receive your password.</td>
</tr>
<tr>
<td align="right" style="width: 30%">
User Name:</td>
<td>
<asp:Literal ID="UserName" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" style="width: 30%">
Question:</td>
<td>
<asp:Literal ID="Question" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" style="width: 30%">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label>
</td>
<td>
<asp:TextBox ID="Answer" runat="server" Width="50%"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Answer is required."
ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</QuestionTemplate>
<SuccessTemplate>
<table cellpadding="0" style="width:100%;">
<tr>
<td align="center">
Your password has been sent to you.</td>
</tr>
</table>
</SuccessTemplate>
<UserNameTemplate>
<table cellpadding="0" width="100%">
<tr>
<td align="center" colspan="2">
Forgot Your Password?</td>
</tr>
<tr>
<td align="center" colspan="2">
Enter your User Name to receive your password.</td>
</tr>
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td align="left" style="width: 70%;">
<asp:TextBox ID="UserName" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit"
ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</UserNameTemplate>
</asp:PasswordRecovery>
<QuestionTemplate>
<table cellpadding="0" style="width:100%;">
<tr>
<td align="center" colspan="2">
Identity Confirmation</td>
</tr>
<tr>
<td align="center" colspan="2">
Answer the following question to receive your password.</td>
</tr>
<tr>
<td align="right" style="width: 30%">
User Name:</td>
<td>
<asp:Literal ID="UserName" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" style="width: 30%">
Question:</td>
<td>
<asp:Literal ID="Question" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" style="width: 30%">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label>
</td>
<td>
<asp:TextBox ID="Answer" runat="server" Width="50%"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Answer is required."
ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</QuestionTemplate>
<SuccessTemplate>
<table cellpadding="0" style="width:100%;">
<tr>
<td align="center">
Your password has been sent to you.</td>
</tr>
</table>
</SuccessTemplate>
<UserNameTemplate>
<table cellpadding="0" width="100%">
<tr>
<td align="center" colspan="2">
Forgot Your Password?</td>
</tr>
<tr>
<td align="center" colspan="2">
Enter your User Name to receive your password.</td>
</tr>
<tr>
<td align="right" style="width: 30%;">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td align="left" style="width: 70%;">
<asp:TextBox ID="UserName" runat="server" style="width: 50%;"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit"
ValidationGroup="PasswordRecovery1" />
</td>
</tr>
</table>
</UserNameTemplate>
</asp:PasswordRecovery>
パスワードのリセット (ペイン 4)
これは、別の記事で設定した CAPTCHA イメージを使用して、自分で作成したカスタム コントロールです。
これを使用したい場合は、以下のコードを使用してください。後で VB を追加します。
HTML
<div style="text-align: center">
<asp:Label ID="Label2" runat="server" Text="Please enter your email address"></asp:Label>
</div>
<div style="text-align: center">
<asp:textbox ID="UserName" runat="server" Width="300px"></asp:textbox>
</div>
<div style="text-align: center">
<img id="captchaImage" src="" alt="" runat="server"/>
<asp:HiddenField ID="CaptchaGuid" runat="server" />
</div>
<div style="text-align: center">
<asp:Label ID="Label1" runat="server" Text="Please enter the value in the image above"></asp:Label>
</div>
<div style="text-align: center">
<asp:textbox ID="CaptchaVal" runat="server" Width="200px"></asp:textbox>
</div>
<div style="text-align: center">
<asp:Button ID="CaptchaSubmit" runat="server" Text="Reset my Password" />
</div>
<div style="text-align: center">
<asp:Label ID="CaptchaResult" runat="server" Text="Please enter the value in the image above"></asp:Label>
</div>
<asp:Label ID="Label2" runat="server" Text="Please enter your email address"></asp:Label>
</div>
<div style="text-align: center">
<asp:textbox ID="UserName" runat="server" Width="300px"></asp:textbox>
</div>
<div style="text-align: center">
<img id="captchaImage" src="" alt="" runat="server"/>
<asp:HiddenField ID="CaptchaGuid" runat="server" />
</div>
<div style="text-align: center">
<asp:Label ID="Label1" runat="server" Text="Please enter the value in the image above"></asp:Label>
</div>
<div style="text-align: center">
<asp:textbox ID="CaptchaVal" runat="server" Width="200px"></asp:textbox>
</div>
<div style="text-align: center">
<asp:Button ID="CaptchaSubmit" runat="server" Text="Reset my Password" />
</div>
<div style="text-align: center">
<asp:Label ID="CaptchaResult" runat="server" Text="Please enter the value in the image above"></asp:Label>
</div>
Web 設定の変更
システムの実行方法に応じて、Web 構成ファイルに以下を追加および変更する必要があります。
YourAppName を入力した場所では、すべてのインスタンスをより適切なものに変更できます。 2 つのメンバーシップ プロバイダーがあり、2 つ目はパスワードのリセットでのみ使用されます。
XML
<configuration>
<connectionStrings>
<add name="MySqlConnection" connectionString="Data Source=.;Initial Catalog=dbname;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login" name=".ASPXFORMSAUTH" defaultUrl="Home"/>
</authentication>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="30">
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" applicationName="YourAppName" enablePasswordRetrieval="false" enablePasswordReset="true" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed"/>
<add name="SqlProviderReset" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" applicationName="YourAppName" enablePasswordRetrieval="false" enablePasswordReset="true" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="YourAppName"/>
</providers>
</profile>
<roleManager defaultProvider="SqlProvider" enabled="true" cacheRolesInCookie="true" cookieName=".gsclaytonnet" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
<providers>
<add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="MySqlConnection" applicationName="YourAppName"/>
</providers>
</roleManager>
</system.web>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="info@gsclayton.net">
<network host="smtp setting" userName="info@email" password="Password" port="Port" />
</smtp>
</mailSettings>
</system.net>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="GSClayton.CaptchaAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="GSClayton.Captcha">
<endpoint address="" behaviorConfiguration="GSClayton.CaptchaAspNetAjaxBehavior" binding="webHttpBinding" contract="GSClayton.Captcha" />
</service>
</services>
</system.serviceModel>
</configuration>
<connectionStrings>
<add name="MySqlConnection" connectionString="Data Source=.;Initial Catalog=dbname;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login" name=".ASPXFORMSAUTH" defaultUrl="Home"/>
</authentication>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="30">
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" applicationName="YourAppName" enablePasswordRetrieval="false" enablePasswordReset="true" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed"/>
<add name="SqlProviderReset" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" applicationName="YourAppName" enablePasswordRetrieval="false" enablePasswordReset="true" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="YourAppName"/>
</providers>
</profile>
<roleManager defaultProvider="SqlProvider" enabled="true" cacheRolesInCookie="true" cookieName=".gsclaytonnet" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
<providers>
<add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="MySqlConnection" applicationName="YourAppName"/>
</providers>
</roleManager>
</system.web>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="info@gsclayton.net">
<network host="smtp setting" userName="info@email" password="Password" port="Port" />
</smtp>
</mailSettings>
</system.net>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="GSClayton.CaptchaAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="GSClayton.Captcha">
<endpoint address="" behaviorConfiguration="GSClayton.CaptchaAspNetAjaxBehavior" binding="webHttpBinding" contract="GSClayton.Captcha" />
</service>
</services>
</system.serviceModel>
</configuration>
負荷およびその他の変数
このコードを修正する必要があり、メタデータを変更する必要があります。 SSL ライセンスがある場合は、コードのコメントを解除して HTTPS にリダイレクトできます。また、View State を利用して、ユーザーが最後にアクセスしたページを記憶します。
VB
Imports System.Data.SqlClient
Imports System.Net.Mail
Inherits System.Web.UI.Page
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString)
Protected Sub Page_Load() Handles Me.Load
Page.Title = "gsclayton.net Sign in"
Page.MetaKeywords = "gsclayton.net, Databases, Web Design, SQL, HTML, .NET, ASP, CSS, Home"
Page.MetaDescription = "gsclayton.net Databases and Web Design, SQL, HTML, .NET, ASP, CSS, Home"
If Not IsPostBack Then
If Not IsNothing(Request.UrlReferrer) Then
ViewState("PreviousPageUrl") = Request.UrlReferrer.ToString()
End If
End If
If Request.IsSecureConnection = False Then
Dim uri As New UriBuilder(Page.Request.Url)
uri.Scheme = System.Uri.UriSchemeHttps 'To redirect to https, uncomment below
'Response.Redirect(uri.ToString())
End If
Dim com As New SqlCommand("EXEC NewCaptchaValue", con)
con.Open()
Dim dr = com.ExecuteReader
Dim valStr As String
Dim valGUID As String = "8375DFCA-7499-4756-A470-CE176C44A02A"
While dr.Read
valGUID = dr.Item(0).ToString()
valStr = dr.Item(0).ToString()
End While
CaptchaGuid.Value = valGUID
captchaImage.Src = ResolveUrl("https://www.gsclayton.net/captcha/" + valGUID)
con.Close()
End Sub
Imports System.Net.Mail
Inherits System.Web.UI.Page
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString)
Protected Sub Page_Load() Handles Me.Load
Page.Title = "gsclayton.net Sign in"
Page.MetaKeywords = "gsclayton.net, Databases, Web Design, SQL, HTML, .NET, ASP, CSS, Home"
Page.MetaDescription = "gsclayton.net Databases and Web Design, SQL, HTML, .NET, ASP, CSS, Home"
If Not IsPostBack Then
If Not IsNothing(Request.UrlReferrer) Then
ViewState("PreviousPageUrl") = Request.UrlReferrer.ToString()
End If
End If
If Request.IsSecureConnection = False Then
Dim uri As New UriBuilder(Page.Request.Url)
uri.Scheme = System.Uri.UriSchemeHttps 'To redirect to https, uncomment below
'Response.Redirect(uri.ToString())
End If
Dim com As New SqlCommand("EXEC NewCaptchaValue", con)
con.Open()
Dim dr = com.ExecuteReader
Dim valStr As String
Dim valGUID As String = "8375DFCA-7499-4756-A470-CE176C44A02A"
While dr.Read
valGUID = dr.Item(0).ToString()
valStr = dr.Item(0).ToString()
End While
CaptchaGuid.Value = valGUID
captchaImage.Src = ResolveUrl("https://www.gsclayton.net/captcha/" + valGUID)
con.Close()
End Sub
ログイン
独自のコントロールを作成した場合は、このコードを再確認してください。ただし、すぐにプラグインする必要があります。次のリンクで私を覚えていることがわかりました。
VB
Private Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
Dim PreviousPageUrl As String = ViewState("PreviousPageUrl")
If Not PreviousPageUrl Is Nothing Then
Dim uri As New UriBuilder(PreviousPageUrl)
uri.Scheme = System.Uri.UriSchemeHttp ' Redirect to https
PreviousPageUrl = uri.ToString
Else
PreviousPageUrl = "home"
End If
If Login1.RememberMeSet = True Then
Response.Cookies.Clear()
'Thanks to for his article-http://blogs.msdn.com/b/friis/archive/2010/08/18/remember-me-checkbox-does-not-work-with-forms-authentication.aspx
Dim ticket As New FormsAuthenticationTicket(Login1.UserName, True, 36000) '25 days, nice round number
Dim ticketEnc As String = FormsAuthentication.Encrypt(ticket)
Dim AuthCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, ticketEnc)
AuthCookie.Expires = ticket.Expiration
Response.Cookies.Add(AuthCookie)
ViewState("PreviousPageUrl") = Nothing
Response.Redirect(ResolveUrl(PreviousPageUrl))
Else
ViewState("PreviousPageUrl") = Nothing
Response.Redirect(ResolveUrl(PreviousPageUrl))
End If
End Sub
Dim PreviousPageUrl As String = ViewState("PreviousPageUrl")
If Not PreviousPageUrl Is Nothing Then
Dim uri As New UriBuilder(PreviousPageUrl)
uri.Scheme = System.Uri.UriSchemeHttp ' Redirect to https
PreviousPageUrl = uri.ToString
Else
PreviousPageUrl = "home"
End If
If Login1.RememberMeSet = True Then
Response.Cookies.Clear()
'Thanks to for his article-http://blogs.msdn.com/b/friis/archive/2010/08/18/remember-me-checkbox-does-not-work-with-forms-authentication.aspx
Dim ticket As New FormsAuthenticationTicket(Login1.UserName, True, 36000) '25 days, nice round number
Dim ticketEnc As String = FormsAuthentication.Encrypt(ticket)
Dim AuthCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, ticketEnc)
AuthCookie.Expires = ticket.Expiration
Response.Cookies.Add(AuthCookie)
ViewState("PreviousPageUrl") = Nothing
Response.Redirect(ResolveUrl(PreviousPageUrl))
Else
ViewState("PreviousPageUrl") = Nothing
Response.Redirect(ResolveUrl(PreviousPageUrl))
End If
End Sub
ユーザーの作成
このコードも直接プラグインする必要があります。これにより、ユーザーは最後にアクセスした URL にリダイレクトされます。
VB
Protected Sub CreateUserWizard1_CreatedUser(sender As Object, e As System.EventArgs) HandlesCreateUserWizard1.CreatedUser
Roles.AddUserToRole(CreateUserWizard1.UserName.ToString, "User")
'Send email etc if desired
Dim PreviousPageUrl As String = ViewState("PreviousPageUrl")
If Not PreviousPageUrl Is Nothing Then
Dim uri As New UriBuilder(PreviousPageUrl)
uri.Scheme = System.Uri.UriSchemeHttp ' Redirect to https
PreviousPageUrl = uri.ToString
Else
PreviousPageUrl = "home"
End If
ViewState("PreviousPageUrl") = Nothing
Response.Redirect(ResolveUrl(PreviousPageUrl))
End Sub
Roles.AddUserToRole(CreateUserWizard1.UserName.ToString, "User")
'Send email etc if desired
Dim PreviousPageUrl As String = ViewState("PreviousPageUrl")
If Not PreviousPageUrl Is Nothing Then
Dim uri As New UriBuilder(PreviousPageUrl)
uri.Scheme = System.Uri.UriSchemeHttp ' Redirect to https
PreviousPageUrl = uri.ToString
Else
PreviousPageUrl = "home"
End If
ViewState("PreviousPageUrl") = Nothing
Response.Redirect(ResolveUrl(PreviousPageUrl))
End Sub
新しいパスワードの送信
追加する最後のサブは Captcha 値をチェックし、正しい場合は新しいランダムに生成されたパスワードを含むメールを送信します。これがセカンダリ プロバイダーを追加した理由です。
VB
Protected Sub CaptchaValue() Handles CaptchaSubmit.Click
Try
Dim valStr As String = Replace(CaptchaVal.Text.ToString, "'", "''")
Dim valGUID As String = Replace(CaptchaGuid.Value, "'", "''")
Dim valEmail As String = Replace(UserName.Text.ToString, "'", "''")
Dim com As New SqlCommand("EXEC CaptchaValue '" & valGUID & "','" & valStr & "'", con)
Dim comu As New SqlCommand("SELECT UserName FROM aspnet_Membership m INNER JOIN aspnet_Users u ON u.UserId=m.UserId WHERE Email='" & valEmail & "'", con)
con.Open()
Dim Result As String = com.ExecuteScalar
Dim GetUser As String = comu.ExecuteScalar
con.Close()
If Result = "Pass" And valEmail <> "" And GetUser <> "" Then
CaptchaResult.Text = "A new password has been generated and sent to your email address"
CaptchaResult.ForeColor = Drawing.Color.Green
Dim mp As MembershipProvider = Membership.Providers("SqlProviderReset")
Dim user As MembershipUser = mp.GetUser(GetUser, False)
Dim pass As String = user.ResetPassword
Dim MailMessage As New MailMessage()
MailMessage.From = New MailAddress("info@gsclayton.net")
MailMessage.To.Add(New MailAddress(valEmail))
MailMessage.IsBodyHtml = True
MailMessage.Subject = "Your New Password"
Dim MailClient As New SmtpClient()
'HTML Format
Dim HTMLViewString As String = "<div>We have reset your password <br /> " +
"User Name: " + GetUser + " <br /> " +
"Password: " + pass + "<br /> " +
"You should change your password on the following <a href="https://ja.claytabase.com/"https://www.gsclayton.net/"">Link</a></div>"
MailMessage.Body = HTMLViewString
MailClient.Send(MailMessage)
Else
CaptchaResult.Text = "Please enter the value correctly and and your email address"
CaptchaResult.ForeColor = Drawing.Color.Red
End If
Catch
CaptchaResult.Text = "Please enter the value correctly and and your email address"
CaptchaResult.ForeColor = Drawing.Color.Red
End Try
End Sub
Try
Dim valStr As String = Replace(CaptchaVal.Text.ToString, "'", "''")
Dim valGUID As String = Replace(CaptchaGuid.Value, "'", "''")
Dim valEmail As String = Replace(UserName.Text.ToString, "'", "''")
Dim com As New SqlCommand("EXEC CaptchaValue '" & valGUID & "','" & valStr & "'", con)
Dim comu As New SqlCommand("SELECT UserName FROM aspnet_Membership m INNER JOIN aspnet_Users u ON u.UserId=m.UserId WHERE Email='" & valEmail & "'", con)
con.Open()
Dim Result As String = com.ExecuteScalar
Dim GetUser As String = comu.ExecuteScalar
con.Close()
If Result = "Pass" And valEmail <> "" And GetUser <> "" Then
CaptchaResult.Text = "A new password has been generated and sent to your email address"
CaptchaResult.ForeColor = Drawing.Color.Green
Dim mp As MembershipProvider = Membership.Providers("SqlProviderReset")
Dim user As MembershipUser = mp.GetUser(GetUser, False)
Dim pass As String = user.ResetPassword
Dim MailMessage As New MailMessage()
MailMessage.From = New MailAddress("info@gsclayton.net")
MailMessage.To.Add(New MailAddress(valEmail))
MailMessage.IsBodyHtml = True
MailMessage.Subject = "Your New Password"
Dim MailClient As New SmtpClient()
'HTML Format
Dim HTMLViewString As String = "<div>We have reset your password <br /> " +
"User Name: " + GetUser + " <br /> " +
"Password: " + pass + "<br /> " +
"You should change your password on the following <a href="https://ja.claytabase.com/"https://www.gsclayton.net/"">Link</a></div>"
MailMessage.Body = HTMLViewString
MailClient.Send(MailMessage)
Else
CaptchaResult.Text = "Please enter the value correctly and and your email address"
CaptchaResult.ForeColor = Drawing.Color.Red
End If
Catch
CaptchaResult.Text = "Please enter the value correctly and and your email address"
CaptchaResult.ForeColor = Drawing.Color.Red
End Try
End Sub
Claytabaseによるウェブサイトのデザイン
これは、当社の Web サイト デザイン サービスの一部である、市場で最も高速で最適化されたシステムの 1 つである Ousia コンテンツ管理システム コードから変更されたコードのセクションです。
これらは、約£500から始まるサイトで利用できます.