Protected Sub CreateUser_Click(sender As Object, e As EventArgs) Dim userName As String = Email.Text Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)() Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)() Dim user = New ApplicationUser() With {.UserName = userName, .Email = userName} Dim result As IdentityResult = manager.Create(user, Password.Text) If result.Succeeded Then ' For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 Dim code As String = manager.GenerateEmailConfirmationToken(user.Id) Dim callbackUrl As String = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request) manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href="">here</a>.") If user.EmailConfirmed Then signInManager.SignIn(user, isPersistent:=True, rememberBrowser:=False) IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response) Else ErrorMessage.Text = "An email has been sent to your account. Please view the email and confirm your account to complete the registration process." End If Else ErrorMessage.Text = result.Errors.FirstOrDefault() End If End Sub
Public Class EmailService Implements IIdentityMessageService Public Function SendAsync(message As IdentityMessage) As Task Implements IIdentityMessageService.SendAsync ' Plug in your email service here to send an email. Dim mm As New MailMessage() mm.From = New MailAddress("emailaddress", "name") mm.To.Add(New System.Net.Mail.MailAddress(message.Destination)) mm.Subject = "Account Created for COSI Data Reporting" mm.Body = "" mm.IsBodyHtml = True Dim smtp As New SmtpClient() smtp.Host = "##.##.###.##" smtp.Port = "###" smtp.Credentials = New System.Net.NetworkCredential("username", "password") ' mm.To.Add(New System.Net.Mail.MailAddress() smtp.Send(mm) Return Task.FromResult(0) End Function End Class
IIdentityMessageService
UserManager
EmailService
mm.Body = ""
callbackUrl
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href="">here</a>.
mm.Subject = message.Subject mm.Body = message.Body
SendEmail
Dim callbackUrl As String = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request) manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href="""">here</a>.")
manager.SendEmail(user.Id, "Confirm your account", $"Please confirm your account by clicking <a href=""{callbackUrl}"">here</a>.")
/Account/Login?ReturnUrl=%2fManage%2fIndex
IdentityHelper.RedirectToReturnUrl
Request.QueryString("ReturnUrl")
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)