ASP.NET webforms VB 使用用户名而不是电子邮件作为用户名

发布于 2025-01-20 00:42:42 字数 2095 浏览 1 评论 0原文

我不想使用电子邮件作为用户名,我修改了代码以添加名字和姓氏,但不能让它使用用户名,它一直在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2025-01-27 00:42:42

您将电子邮件 ID 存储在用户名中。如果您不想使用电子邮件作为用户名,那么您必须使用此

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

You are storing Email Id in userName. if you don't want to use email as user name then you have to use this

 Dim userName As String = TextBoxFname.Text +"   "+.Surname = TextBoxSName.Text
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文