I have an asp.net MVC project with authentication. The default implementation uses email address for either registering users or logging them in, but in my project I don't need their email address and I want to use simple string username, therefore I have included the following code in my OnModelCreating method to exclude email addresses and some other features that I don't need:
modelBuilder.Entity<ApplicationUser>().Ignore(p => p.AccessFailedCount).
Ignore(p => p.Email).Ignore(p => p.EmailConfirmed).Ignore(p => p.LockoutEnabled).
Ignore(p => p.LockoutEndDateUtc).Ignore(p => p.PhoneNumber).
Ignore(p => p.PhoneNumberConfirmed).Ignore(p => p.TwoFactorEnabled);
I have changed the LoginViewModel and Login.cshtml and replaced email address fields with username, but when I try to login an exception is raised in Login action in the following line:
var result = await SignInManager.PasswordSignInAsync(model.Username, model.Password,
model.RememberMe, shouldLockout: false);
The error page says:
The property 'Email' is not a declared property on type 'ApplicationUser'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.
The question is how can I completely exclude email?