ASP.Net UserName to Email

后端 未结 7 760
北海茫月
北海茫月 2020-11-29 06:35

I am working with the new ASP.NET Identity (RTM) and I was wondering how would I go on about changing registering and login from being a UserName to an Email.

The id

7条回答
  •  没有蜡笔的小新
    2020-11-29 07:10

    I get this working.

    First go to accountViewModels and add a Property for the UserName

    Public Class RegisterViewModel
        
        
        Public Property UserName As String
    
        
        
        
        Public Property Email As String
    

    After modify your Register view adding the username property

    @Html.LabelFor(Function(m) m.UserName, New With {.class = "col-md-2 control-label"})
    @Html.TextBoxFor(Function(m) m.UserName, New With {.class = "form-control"})
    @Html.LabelFor(Function(m) m.Email, New With {.class = "col-md-2 control-label"})
    @Html.TextBoxFor(Function(m) m.Email, New With {.class = "form-control"})

    Once this is done, modify too your Login view

                    @Html.ValidationSummary(True, "", New With {.class = "text-danger"})
                
    @Html.Label("User Name", New With {.class = "col-md-2 control-label"})
    @Html.TextBoxFor(Function(m) m.Email, New With {.class = "form-control"}) @Html.ValidationMessageFor(Function(m) m.Email, "", New With {.class = "text-danger"})
    @Html.LabelFor(Function(m) m.Password, New With {.class = "col-md-2 control-label"})
    @Html.PasswordFor(Function(m) m.Password, New With {.class = "form-control"}) @Html.ValidationMessageFor(Function(m) m.Password, "", New With {.class = "text-danger"})

    That is all you need. This way you can LogIn with the UserName not with the email address.

提交回复
热议问题