ASP.NET webforms VB 使用用户名而不是电子邮件作为用户名
我不想使用电子邮件作为用户名,我修改了代码以添加名字和姓氏,但不能让它使用用户名,它一直在aspnetusers
表中使用电子邮件,
我喜欢用户使用其用户名导航到其他用户并保留电子邮件机密
Protected Sub Unnamed4_Click(sender As Object, e As EventArgs)
If Me.Password.Text = Me.ConfirmPassword.Text Then
Dim userName As String = signinSrEmail.Text
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
Dim user = New ApplicationUser() With {.UserName = userName, .Email = userName, .FirstName = TextBoxFname.Text, .Surname = TextBoxSName.Text}
Dim result = manager.Create(user, Password.Text.ToString)
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 = manager.GenerateEmailConfirmationToken(user.Id)
Dim callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request)
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>.")
If user.EmailConfirmed Then
'Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
FormsAuthentication.SetAuthCookie(user.Id, False)
signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=True)
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
Else
errormessage.Text = "Passwords do not match"
End If
End Sub
End Class
I don't want use email as username, I amended the code to add first name and last name but cant get it to use usernames, it keeps going to email in aspnetusers
table
I'd like the users to navigate to other users using their username and keeping emails confidential
Protected Sub Unnamed4_Click(sender As Object, e As EventArgs)
If Me.Password.Text = Me.ConfirmPassword.Text Then
Dim userName As String = signinSrEmail.Text
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
Dim user = New ApplicationUser() With {.UserName = userName, .Email = userName, .FirstName = TextBoxFname.Text, .Surname = TextBoxSName.Text}
Dim result = manager.Create(user, Password.Text.ToString)
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 = manager.GenerateEmailConfirmationToken(user.Id)
Dim callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request)
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>.")
If user.EmailConfirmed Then
'Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
FormsAuthentication.SetAuthCookie(user.Id, False)
signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=True)
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
Else
errormessage.Text = "Passwords do not match"
End If
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将电子邮件 ID 存储在用户名中。如果您不想使用电子邮件作为用户名,那么您必须使用此
You are storing Email Id in userName. if you don't want to use email as user name then you have to use this