1

我正嘗試在asp.net中使用創建用戶嚮導來基於這篇文章創建新帳戶www.4guysfromrolla.com/articles/062508-1.aspx,禁用他的帳戶以立即登錄併發送註冊後立即通過電子郵件進行驗證,一切正常。用戶ID的電子郵件驗證問題

對不起,我不能上傳沒有min rep的圖片,所以我現在只能提供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("[email protected]", "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 

回答

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 [email protected] ", 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