ASP.NET Web窗体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

您正在将电子邮件Id存储在用户名中。如果你不想使用电子邮件作为用户名,那么你必须使用这个

Dim userName As String = TextBoxFname.Text +"   "+.Surname = TextBoxSName.Text

相关内容

最新更新