Reputation: 45704
I am using the default authentication system created by ASP.NET Core, and I'd like to know ?
how to change the name of the ASPNETUsers
table to User
?
How to add the following property to the table: public string DisplayName {get; set;}
How to add the RemoteAttribute
attribute to the Email property
Is it a good idea to create another table, named Profile, with a one-to-one relationship with the ASPNETUsers table, if I have a few properties ?
thanks...
Upvotes: 5
Views: 1753
Reputation: 65938
You can do those as shown below.
1.
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationUser>(entity =>
{
entity.ToTable(name:"User");
});
}
2.
public class ApplicationUser : IdentityUser
{
......................
......................
public string DisplayName {get; set;}
}
3. I would like to suggest you to put that on your ViewModel
instead of the Core model (i.e. ApplicationUser )
as shown below.
using Microsoft.AspNet.Mvc;
using System.ComponentModel.DataAnnotations;
public class LoginViewModel
{
[Required]
[EmailAddress]
[Remote("Foo", "Home", ErrorMessage = "Remote validation is working for you")]
public string Email { get; set; }
}
4. Hence you have only few properties,you can keep those properties inside the ASPNETUsers
table itself. Which is easy to maintain :)
Upvotes: 5