私はVS2012をデータベースプロバイダーとして使用しASP.NET 4.5
てMySQL
います。ある時点で正常に機能していたコードで、指定されたキャストエラーが発生します。これは、登録検証用の私のRegister.aspxページからのものであり、コードはasp.netWebサイトのチュートリアルから採用されています。
これがコードです、エラーは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