Error: "The Id field is required." while registering new user in database with AspNet.Identity 2.0

asp.net-identity asp.net-mvc c# entity-framework-6

Question

Welcome,

I get the validation error mentioned in topic while creating (registering) new user in my Asp.Net mvc application where I used Asp.Net Identity with my custom ApplicationUser class

public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
    public async Task<ClaimsIdentity>
    GenerateUserIdentityAsync(ApplicationUserManager manager)
    {      
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);   
        return userIdentity;
    }

    public virtual string EmailConfirmedChar { get; set; }

    public virtual string PhoneNumberConfirmedChar { get; set; }

    public virtual string TwoFactorEnabledChar { get; set; }

    public virtual string LockoutEnabledChar { get; set; }
}

where my TKey is string, so I expect the Id to be Guid as it is by default.

Of course I implemented my custom UserStore, UserManager etc, in general I inspired by the blog post Customizing the ASP.NET Identity Data Model with the Entity Framework Fluent API

What do I do wrong ? Generaly the same validation error appears while downloaded the sample attached in this blog post.

Relevant or nor, I use Firebird database.

1
2
9/19/2015 5:40:29 PM

Accepted Answer

IdentityUser class automatically generates GUID when you make a new instance of it. Not IdentityUser<TKey, TLogin, TRole, TClaim> class. However you could easily overcome this problem by generating new GUID in your ApplicationUser class constructor:

public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
    public ApplicationUser()
    {
        Id = Guid.NewGuid().ToString();
    }
    // rest of code
}
10
9/19/2015 7:39:03 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow