相关疑难解决方法(0)

如何在使用ASP.NET标识时更改表名?

我正在使用Visual Studio 2013的发布版本(RTM,而不是RC)(从MSDN 2013-10-18下载),因此使用AspNet.Identity的最新版本(RTM).当我创建一个新的Web项目时,我选择"个人用户帐户"进行身份验证.这将创建以下表:

  1. AspNetRoles
  2. AspNetUserClaims
  3. AspNetUserLogins
  4. AspNetUserRoles
  5. AspNetUsers

当我注册一个新用户(使用默认模板)时,会创建这些表(如上所列),并且AspNetUsers表中插入了一条记录,其中包含:

  1. ID
  2. 用户名
  3. PasswordHash
  4. SecurityStamp
  5. 鉴别

此外,通过向"ApplicationUser"类添加公共属性,我已成功向AspNetUsers表添加了其他字段,例如"FirstName","LastName","PhoneNumber"等.

这是我的问题.有没有办法更改上面表格的名称(首次创建时)或者它们是否总是以AspNet我上面列出的前缀命名?如果表名可以不同的名称,请解释如何.

- 更新 -

我实施了@Hao Kung的解决方案.它确实创建了一个新表(例如我称之为MyUsers),但它仍然创建了AspNetUsers表.目标是用"MyUsers"表替换"AspNetUsers"表.请参阅下面的代码和创建的表的数据库图像.

我实际上想AspNet用我自己的名字替换每个表...例如,MyRoles,MyUserClaims,MyUserLogins,MyUserRoles和MyUsers.

我如何实现这一目标,最终只有一组表格?

public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string PostalCode { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-identity

206
推荐指数
5
解决办法
9万
查看次数

如何更改asp.net identity 3(vnext)使用的表名?

在asp.net身份2中用于更改身份表名称的方法在asp.net身份3中不起作用.

asp.net asp.net-identity asp.net-identity-3

5
推荐指数
1
解决办法
1907
查看次数

如何强制Asp.Net Identity 2.0使用自定义角色而不是IdentityUserRole

我扩展了IdentityUserRole,如下所示

public class ApplicationUserRoles : IdentityUserRole<string>
{
    [Key]
    public string ApplicationId { get; set; }

    public virtual AspNetApplications AspNetApplications { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的AspNetApplications类如下

public class AspNetApplications
{
    [Key]
    public string ApplicationId { get; set; }
    public string ApplicationName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

迁移已在DB中创建了AspNetApplications和ApplicationUserRoles表.屏幕截图如下.

在此输入图像描述

以下是我的身份模型

public class ApplicationUser : IdentityUser
{
    public virtual AspNetApplications AspNetApplication { get; set; }
    public virtual ApplicationUserRoles AspNetUserRoles { get; set; }
    //public virtual ICollection<AspNetApplicationUsers> AspNetApplicationUsers { get; set; }

    public async Task<ClaimsIdentity> …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc roles asp.net-identity asp.net-identity-2

3
推荐指数
1
解决办法
2498
查看次数