ここから取得した単純なユーザー作成ウィザードとカスタムメンバーシッププロバイダーがあります
今、私はscott Mitchellによるこのチュートリアルに従い、ウィザードを使用して新しいユーザーを作成し、[プロパティユーザーの作成を無効にする]を[False]に設定してメールを送信できるようにします。これにより、ユーザーがアクティベーションリンクを受信するたびに、それをクリックしてアカウントを確認する必要があります。
ここで問題となるのは、新しいユーザーを作成すると正常に機能し、すぐにログインしようとすると、ログインするために最初にリンクを有効にする必要があるというメッセージが表示されることです。
登録後、彼は電子メールを受け取り、リンクをクリックすると、データベースにユーザーがいないというエラーが表示されます。
以下に示すように、そのユーザーはアクティベーションリンクを取得します
ユーザーがクリックしようとすると、データベースに見つからないことがわかります。
また、管理ツールをチェックインした場合、チェックした場合、ユーザーは横にチェックマークがなくても利用できます。
これが私のweb.configです。
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="HDIConnectionString"
connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|HDIMembershipProvider.mdf"/>
</connectionStrings>
<system.web>
<roleManager defaultProvider="CustomProvider">
<providers>
<add connectionStringName="HDIConnectionString" name="CustomProvider"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
<membership defaultProvider="HDIMembershipProvider">
<providers>
<clear/>
<add name="HDIMembershipProvider" type="HDI.AspNet.Membership.HDIMembershipProvider" connectionStringName="HDIConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear"/>
</providers>
</membership>
<machineKey validationKey="C50B3C89CB21F4F1422FF158A5B42D0E8DB8CB5CDA1742572A487D9401E3400267682B202B746511891C1BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE" decryptionKey="8A9BE8FD67AF6979E7D20198CFEA50DD3D3799C77AF2B72F" validation="SHA1"/>
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="Login.aspx" />
</authentication>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
<appSettings>
<add key="adminEmail" value="noreply@xyz.com"/>
</appSettings>
<system.net>
<mailSettings>
<smtp from="xyz@gmail.com">
<network host="smtp.gmail.com" password="password" port="587" userName="xyz@gmail.com"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
そして、createuser.aspxのコードビハインド:
Protected Sub CreateUserWizard1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles CreateUserWizard1.SendingMail
Dim userInfo As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
'Construct the verification URL
Dim verifyUrl As String = Request.Url.GetLeftPart(UriPartial.Authority) & Page.ResolveUrl("~/Verify.aspx?ID=" & userInfo.ProviderUserKey.ToString())
'Replace <%VerifyUrl%> placeholder with verifyUrl value
e.Message.Body = e.Message.Body.Replace("<%VerifyUrl%>", verifyUrl)
End Sub
Page_Loadを確認します。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Make sure that a valid querystring value was passed through
If String.IsNullOrEmpty(Request.QueryString("ID")) OrElse Not Regex.IsMatch(Request.QueryString("ID"), "[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}") Then
InformationLabel.Text = "An invalid ID value was passed in through the querystring."
Else
'ID exists and is kosher, see if this user is already approved
'Get the ID sent in the querystring
Dim userId As Guid = New Guid(Request.QueryString("ID"))
'Get information about the user
Dim userInfo As MembershipUser = Membership.GetUser(userId)
If userInfo Is Nothing Then
'Could not find user!
InformationLabel.Text = "The user account could not be found in the membership database."
Else
'User is valid, approve them
userInfo.IsApproved = True
Membership.UpdateUser(userInfo)
'Display a message
InformationLabel.Text = "Your account has been verified and you can now log into the site."
End If
End If
そして、これがデータベースのスクリーンショットです: