【问题标题】:Value cannot be null. Parameter name: value值不能为空。参数名称:值
【发布时间】:2017-03-11 10:49:42
【问题描述】:

我想在 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; }

}

出现以下错误 值不能为空。 参数名称:值

      {
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

【问题讨论】:

  • @TAHA SULTAN TEMURI 您能否更详细地解释您获得赏金的原因?这个问题已经很老了,看起来已经得到了充分的回答(尽管 OP 没有接受)。
  • 实际上我几周前遇到了同样的问题,所以我决定开始赏金,然后我找到了解决方案,这就是为什么现在等待关闭。

标签: asp.net asp.net-identity customization


【解决方案1】:

我通过在 SecurityStamp 字段中放置一个随机字符串解决了这个问题。要生成此字符串,只需使用 Guid.NewGuid ()

因此,您可以将代码更改为: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;
}

【讨论】:

    【解决方案2】:

    我也面临同样的错误。当我将[Display] 更改为此时,我发现在Model 中:

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

    而不是这个:

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

    名称的value 未定义...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 2014-05-17
      • 2016-05-14
      • 2015-11-05
      • 2019-05-26
      相关资源
      最近更新 更多