简体   繁体   中英

Value cannot be null. Parameter name: value

i want to add new field in aspnet user table ..i have also added username property in account view model ..

 public class ApplicationUser : IdentityUser<int, UserLogin, UserRole, UserClaim>
{
    public DateTime? ActiveUntil;

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
    {
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        return userIdentity;
    }
    public string  UserName { get; set; }

}

It is giving following error Value cannot be null. Parameter name: value

      {
Line 53:             // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
Line 54:             var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
Line 55:             // Add custom user claims here

I solved this problem by putting a random string in the SecurityStamp field. To generate this string simply use Guid.NewGuid ()

So, you can change your code to something like this: enter code here

public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
{
    if (string.IsNullOrEmpty(this.SecurityStamp))
    {
        this.SecurityStamp = Guid.NewGuid().ToString().Replace("-", "");
    }

    var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
    return userIdentity;
}

I also face the same error. I found that in the Model when I change [Display] to this:

[Display(Name = "")]
public string Budget { get; set; }

Instead of this:

[Display(Name = "Budget")]
public string Budget { get; set; }

The value of name is not defined...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM