我将 VS2012 与ASP.NET 4.5
我MySQL
的数据库提供程序一起使用。我现在在某个时间运行良好的代码上收到一个指定的转换错误。它来自我用于注册验证的 Register.aspx 页面,代码改编自 asp.net 网站教程。
这是代码,错误就Dim newUser as Guid
行了
Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)
Dim newUser As MembershipUser = Membership.GetUser(RegisterUser.UserName)
Dim newUserID As Guid = DirectCast(newUser.ProviderUserKey, Guid)
Dim urlBase As String = Request.Url.GetLeftPart(UriPartial.Authority) & Request.ApplicationPath
Dim verifyUrl As String = "VerifyNewUser.aspx?ID=" & newUserID.ToString()
Dim fullPath As String = urlBase & verifyUrl
Dim appPath As String = Request.PhysicalApplicationPath
Dim sr As New StreamReader(appPath & "EmailTemplates/VerifyUserAccount.txt")
Dim mailMessage As New MailMessage()
mailMessage.IsBodyHtml = True
mailMessage.From = New MailAddress("myacct@gmail.com")
mailMessage.To.Add(New MailAddress(RegisterUser.Email))
mailMessage.CC.Add(New MailAddress("myacct@gmail.com"))
mailMessage.Subject = "New User Registration"
mailMessage.Body = sr.ReadToEnd
sr.Close()
mailMessage.Body = mailMessage.Body.Replace("<%UserName%>", RegisterUser.UserName)
mailMessage.Body = mailMessage.Body.Replace("<%VerificationUrl%>", fullPath)
//Set up the smtp for gmail to send the email
Dim mailClient As New SmtpClient()
With mailClient
.Port = 587 'try 465 if this doesn't work
.EnableSsl = True
.DeliveryMethod = SmtpDeliveryMethod.Network
.UseDefaultCredentials = False
.Credentials = New NetworkCredential(mailMessage.From.ToString(), "password")
.Host = "smtp.gmail.com"
End With
mailClient.Send(mailMessage)
Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
If String.IsNullOrEmpty(continueUrl) Then
continueUrl = "~/"
End If
Response.Redirect(continueUrl)
End Sub