身份更改GUID为int

前端之家收集整理的这篇文章主要介绍了身份更改GUID为int前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将AspNetUser表的PK列从guid更改为int数据类型?
现在可以使用今天发布的最新的asp.net身份版本.

但是我找不到任何地方怎么办?

解决方法

默认情况下,ASP.NET身份(使用实体框架)使用字符串作为主键,而不是GUID,但它会将GUID存储在这些字符串中.

您需要定义更多的类,我刚刚创建了一个新项目(我正在使用VS2013 Update 2 CTP),以下是需要更改的身份模型:

public class ApplicationUser : IdentityUser<int,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim>
{
    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;
    }
}

public class ApplicationUserRole : IdentityUserRole<int>
{
}

public class ApplicationUserLogin : IdentityUserLogin<int>
{
}

public class ApplicationUserClaim : IdentityUserClaim<int>
{
}

public class ApplicationRole : IdentityRole<int,ApplicationUserRole>
{
}

public class ApplicatonUserStore :
    UserStore<ApplicationUser,ApplicationRole,int,ApplicationUserClaim>
{
    public ApplicatonUserStore(ApplicationDbContext context)
        : base(context)
    {
    }
}

public class ApplicationDbContext
    : IdentityDbContext<ApplicationUser,ApplicationUserClaim>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

您还需要更新其他几个地方,只需按照编译错误,最常见的更改将是将从User.Identity.GetUserId()返回的字符串转换为整数.

另外,在回答another question(我没有问过这个问题的时候),我提供了一个例子,解决这个问题,看看下面的资料库:

https://github.com/JSkimming/AspNet.Identity.EntityFramework.Multitenant

原文链接:https://www.f2er.com/aspnet/250510.html

猜你在找的asp.Net相关文章