gpt4 book ai didi

asp.net - 值不能为空。参数名称 : value

转载 作者:行者123 更新时间:2023-12-01 06:03:15 24 4
gpt4 key购买 nike

我想在aspnet用户表中添加新字段..我还在帐户 View 模型中添加了用户名属性..

 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

最佳答案

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

关于asp.net - 值不能为空。参数名称 : value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42734275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com