身份更改GUID为int
发布时间:2020-05-24 01:52:54 所属栏目:asp.Net 来源:互联网
导读:如何将AspNetUser表的PK列从guid更改为int数据类型? 现在可以使用今天发布的最新的asp.net身份版本. 但是我找不到任何地方怎么办? 默认情况下,ASP.NET身份(使用实体框架)使用字符串作为主键,而不是GUID,但它会将GUID存储在这些字符串中. 您需要定义更多的类
|
如何将AspNetUser表的PK列从guid更改为int数据类型?
但是我找不到任何地方怎么办? 解决方法默认情况下,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 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如何单元测试MSTest中的JsonResult和集合
- asp.net-mvc – Html.BeginForm的默认区域是否始终是ASP.NE
- asp.net – 来自masterpage的Html.RenderPartial调用
- asp.net-mvc – 存储库与DAL中的服务模式:EF和Dapper
- asp.net – 我可以在GoDaddy上使用NHibernate吗?
- 在ASP.NET中如何处理未处理的异常?
- asp.net-mvc-3 – dataannotations在主键上设置标识种子值,
- asp.net-mvc – 如何最好在服务器上安装MVC 3?
- ASP.Net 4.0中可用的新功能是什么?
- 如何配置asp.net与.net 4.5
推荐文章
站长推荐
热点阅读
