I have followed the instructions here to extend asp.net identity to use an int instead of a string for the user Id as I am adding identity to an existing database.
However, when I attempt to login I am getting the error: The 'Id' property on 'IdentityRole`2' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.Int32'.
That happens in this class:
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
{
return Task.FromResult(GenerateUserIdentity(manager));
}
public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = manager.CreateIdentity<ApplicationUser, int>(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
on the line
var userIdentity = manager.CreateIdentity<ApplicationUser, int>(this, DefaultAuthenticationTypes.ApplicationCookie);
If you get a similar issue to this, it was that the Database was out of sync with the models, so I needed to change the RoleId in the AspNetRoles (and AspNetUserRoles) to an int in this case also.