1

この記事www.4guysfromrolla.com/articles/062508-1.aspxに基づいて新しいアカウントを作成するために、asp.netでユーザー作成ウィザードを使用しようとしています。彼のアカウントを無効にして、すぐにログインし、登録後すぐに関連する電子メールに電子メールを送信します検証のために、すべてがうまく機能します。

申し訳ありませんが、最小担当者がいないと画像をアップロードできないため、今のところ 2 つのリンクしか提供できません。

ここで問題は、URL に含まれるUSERIDを使用してユーザーに送信される電子メールです。

そして、次のようにデータベースに追加する方法を示します。

http://img829.imageshack.us/img829/4410/54303910.png

ユーザーが無効になっているため、Asp.Net構成では次のように表示されます。

http://img41.imageshack.us/img41/9286/74707709.png

上の画像でわかるように、ユーザー名の横にチェックマークがありません (つまり、ユーザーは無効になっており、メール認証を使用してアカウントを有効にする必要があります)。

したがって、ユーザーがクリックをクリックすると、user is not found in the database.

私はこれに本当に困惑しており、ネット上のすべての人が電子メールを送信するための同じ記事を見せてくれました. しかし、どれも機能しませんでした。

または、私は何か間違ったことをしていますか?皆さんの何人かによって私に光を当てたいと思います。

ユーザーを作成してメールを送信するための私のコードは次のとおりです。

 Protected Sub CreateUserWizard1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles CreateUserWizard1.SendingMail
    Dim newUserAccount As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
    Dim newUserAccountId As Guid = DirectCast(newUserAccount.ProviderUserKey, Guid)
    Dim domainName As String = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath
    Dim confirmationPage As String = "EmailConfirmation.aspx?UserID=" & newUserAccountId.ToString()
    Dim url As String = domainName & confirmationPage
    e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", url)
    Dim smtp As New SmtpClient()
    smtp.Host = "smtp.gmail.com"
    smtp.Port = 587
    smtp.UseDefaultCredentials = False
    smtp.Credentials = New System.Net.NetworkCredential("myemail@gmail.com", "gmailpassword")
    smtp.EnableSsl = True
    smtp.Send(e.Message)
    e.Cancel = True
End Sub

メール確認.aspx:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    'Make sure that a valid querystring value was passed through
    If String.IsNullOrEmpty(Request.QueryString("UserID")) OrElse Not Regex.IsMatch(Request.QueryString("UserID"), "[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}") Then
        lblMessage.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("UserID"))

        'Get information about the user
        Dim userInfo As MembershipUser = Membership.GetUser(userId)
        If userInfo Is Nothing Then
            'Could not find user!
            lblMessage.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
            lblMessage.Text = "Your account has been verified and you can now log into the site."
        End If
    End If
End Sub
4

1 に答える 1

0

これは私のために働いた解決策です

 Dim ConString As String = ConfigurationManager.ConnectionStrings("HDIConnectionString").ConnectionString
    Dim UserID As String
    Dim i As Integer = 0

    If (Request.QueryString("UserID") IsNot Nothing) Then
        UserID = Request.QueryString("UserID")
        Dim con As New SqlConnection(ConString)
        Dim cmd As New SqlCommand("UPDATE Users SET IsApproved=1 WHERE UserID=@UserID ", con)
        cmd.Parameters.AddWithValue("@UserID", UserID)
        con.Open()
        i = cmd.ExecuteNonQuery()
        con.Close()
    End If
    If i > 0 Then
        lblMessage.Text = "Your account has been approved. Please <a href=""Login.aspx"">login</a> to the site."
    Else
        lblMessage.Text = "User account could not be found..."
    End If
于 2013-03-04T15:25:12.767 に答える