Quo*_*ter 14 int guid asp.net-identity
如何将AspNetUser表的PK列从a guid更改为int数据类型?现在应该可以使用asp.net-identity今天发布的最新版本.
但我无法在任何地方找到这样做的方法?
Jam*_*ing 15
默认情况下,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, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicatonUserStore(ApplicationDbContext context)
: base(context)
{
}
}
public class ApplicationDbContext
: IdentityDbContext<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
Run Code Online (Sandbox Code Playgroud)
您还需要更新其他几个地方,只需按照编译错误,最常见的更改将是将User.Identity.GetUserId()返回的字符串转换为整数.
另外,在回答另一个问题时(虽然我确实提出过这个问题),我提供了一个示例解决方案来做到这一点,请参阅下面的存储库:
https://github.com/JSkimming/AspNet.Identity.EntityFramework.Multitenant
如果有人在寻找Identity 3.0指南时发现了此问题:
public class ApplicationUser : IdentityUser<int>
{
}
public class ApplicationRole : IdentityRole<int>
{
}
public class ApplicationDbContext:
IdentityDbContext<ApplicationUser, ApplicationRole, int>
{
}
Run Code Online (Sandbox Code Playgroud)
在Startup.cs文件中,ConfigureServices方法:
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext, int>()//, int being the only difference
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
仅此而已,无需像2.0中那样创建您的经理
在此博客文章中找到了此内容。
| 归档时间: |
|
| 查看次数: |
11152 次 |
| 最近记录: |