简体   繁体   English

带有UserID的电子邮件验证问题

[英]Email Verification Issue with UserID

I am trying to use create user wizard in asp.net for creating new accounts based on this article www.4guysfromrolla.com/articles/062508-1.aspx, disabled his account for immediate login and send email immediately after registration to the concerned email for verification and everything works well. 我试图根据本文www.4guysfromrolla.com/articles/062508-1.aspx在asp.net中使用创建用户向导创建新帐户,禁用他的帐户以立即登录并在注册到相关电子邮件后立即发送电子邮件进行验证,一切正常。

Sorry guys I cannot upload images without min rep so I'm only able to provide 2 links for now. 抱歉,如果没有分钟回复,我将无法上传图片,因此我现在只能提供2个链接。

Now the problem is email sent to the user with the url included USERID : 现在的问题是发送给用户的电子邮件包含USERID

And here is how it added to the database as shown: 如下所示,它是如何添加到数据库中的:

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

Now in the Asp.Net configuration as the user is disabled it is shown as below: 现在,在禁用用户的Asp.Net配置中,如下所示:

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

As you can see in the above image there is no tick mark checked beside the username(that means the user is disabled and he needs to activate his account using email verfication) 如上图所示,用户名旁边没有勾选任何勾号(这意味着该用户已被禁用,他需要使用电子邮件验证来激活其帐户)

So Once when the user clicks the click it gives me that the user is not found in the database . 因此,一旦用户单击该单击,它就会告诉我user is not found in the databaseuser is not found in the database

I am really stumped with this and every one on the net showed me the same article for sending email. 我对此感到非常困惑,网上的每个人都向我展示了同一封发送电子邮件的文章。 But none of them worked. 但是他们都不起作用。

Or Am I doing anything wrong? 还是我做错了什么? I want to shed some light on me by some of you guys. 我想让你们中的一些人了解我。

Here is my code for creating user and sending email: 这是我用于创建用户和发送电子邮件的代码:

 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: 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

This is the solution worked for me 这是为我工作的解决方案

 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM