欢迎光临,
在我的Asp中创建(注册(新用户时,我收到了主题中提到的验证错误。Net mvc应用程序,我在其中使用了Asp。Net Identity与我的自定义ApplicationUser类
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; }
}
其中我的TKey
是字符串,所以我希望Id
默认为Guid
。
当然,我实现了我的自定义UserStore,UserManager等,总的来说,我的灵感来自博客文章自定义ASP。NET身份数据模型的实体框架Fluent API
我做错了什么?通常,在下载本博客文章中附带的示例时会出现相同的验证错误。
相关或否,我使用火鸟数据库。
IdentityUser
类在创建新实例时自动生成GUID。不IdentityUser<TKey, TLogin, TRole, TClaim>
类。然而,您可以通过在ApplicationUser
类构造函数中生成新的GUID来轻松克服这个问题:
public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationUser()
{
Id = Guid.NewGuid().ToString();
}
// rest of code
}