![](/img/trans.png)
[英]asp.net identity, mapping error after change pk field to int and table names
[英]ASP.NET Identity 2.1 change PK to int error
我按照http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity中的说明更改了PK,但是在我尝试登录后,我得到了跟随错误。 登录部分成功,因为“this”包含所有相关数据,但创建身份似乎失败
从物化的“System.String”类型到“System.Int32”类型的指定强制转换无效。
在线
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
方法
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public string FirstName { get; set; }
public string LastName { get; set; }
}
清除你的cookies。 您可能在更改PK之前运行了应用程序,现在尝试使用cookie中的其他“密钥类型”登录。
根据您的来源,我假设您正在使用ApplicationUserManager来管理所有配置。 使用ApplicationUserManager而不是UserManager,如下所示。 在owin startUp中使用GenerateUserIdentityAsync方法的原因。
使用ApplicationUserManager而不是UserManager。
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.