简体   繁体   English

值不能为空。 参数名称:值

[英]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 ..我想在aspnet用户表中添加新字段..我还在帐户视图模型中添加了用户名属性..

 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.我通过在 SecurityStamp 字段中放置一个随机字符串解决了这个问题。 To generate this string simply use Guid.NewGuid ()要生成此字符串,只需使用 Guid.NewGuid ()

So, you can change your code to something like this: enter code here因此,您可以将代码更改为如下所示: 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]更改为这个时,我发现在Model

[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...名称的value未定义...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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