ASP.NET 2.1身份改变PK为int错误 [英] ASP.NET Identity 2.1 change PK to int error

查看:557
本文介绍了ASP.NET 2.1身份改变PK为int错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经改变了PK中的 http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity ,但是经过我尝试登录,我得到的下面的错误。登录部分是成功的,因为这个包含了所有approperate数据,但创造的身份似乎失败



从物化'System.String'指定的强制转换类型的'System.Int32'类型无效。



在该行

  VAR的UserIdentity =等待manager.CreateIdentityAsync(这一点,DefaultAuthenticationTypes.ApplicationCookie); 



该方法



 公共类ApplicationUser:IdentityUser< INT,CustomUserLogin,CustomUserRole,CustomUserClaim> 
{
公共异步任务< ClaimsIdentity> GenerateUserIdentityAsync(的UserManager< ApplicationUser,INT>经理)
{
//注意authenticationType必须CookieAuthenticationOptions.AuthenticationType
变种的UserIdentity =定义的匹配等待manager.CreateIdentityAsync(这一点,DefaultAuthenticationTypes.ApplicationCookie );
//添加自定义的用户要求在这里
返回的UserIdentity;
}
公共字符串名字{获得;组; }
公共字符串名字{获得;组; }

}


解决方案

我有同样的问题以及..唯一的区别是,在我的错误是 AddToRole AddToRoleAsync




从物化System.String类型指定的强制转换到'System.Int32'类型无效。




出错的行为:等待UserManager.AddToRoleAsync(user.Id,model.RoleId);



事实证明,我需要更改表的键 AspNetRoles ,以及......也许这幅画使得它更清晰。




I have changed the PK as described in http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity, however after I try to login, i get the following error. The login part is successful because "this" contains all the approperate data, however creating identity seems to fail

The specified cast from a materialized 'System.String' type to the 'System.Int32' type is not valid.

at the line

var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

of the method

 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; }

}

解决方案

I had the same problem as well.. the only difference is that my error is during AddToRole or AddToRoleAsync.

The specified cast from a materialized 'System.String' type to the 'System.Int32' type is not valid.

The offending line is at: await UserManager.AddToRoleAsync(user.Id, model.RoleId);

As it turns out, I need to change the key for table AspNetRoles as well... perhaps this picture makes it clearer..

这篇关于ASP.NET 2.1身份改变PK为int错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆