【问题标题】:Email Verification Issue with UserID用户 ID 的电子邮件验证问题
【发布时间】:2013-02-15 13:17:18
【问题描述】:

我正在尝试使用 asp.net 中的创建用户向导根据这篇文章 www.4guysfromrolla.com/articles/062508-1.aspx 创建新帐户,禁用他的帐户以立即登录并在注册后立即发送电子邮件至相关电子邮件进行验证,一切正常。

对不起各位,我不能上传图片没有 min rep 所以我现在只能提供 2 个链接。

现在问题是发送给用户的电子邮件,其中包含 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

EmailConfirmation.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

【问题讨论】:

    标签: asp.net createuserwizard custom-membershipprovider email-verification


    【解决方案1】:

    这是适合我的解决方案

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 2019-06-16
      • 1970-01-01
      • 2016-06-13
      • 2017-10-23
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多