简体   繁体   English

创建注册表格和角色asp mvc身份

[英]create registration form and roles asp mvc identity

I'm very confused about creating registration form. 我对创建注册表很困惑。 I am building a shopping cart website and i want users to register on my website. 我正在建立一个购物车网站,我希望用户在我的网站上注册。 for this i have user table in my DB, also an admin table. 为此,我在数据库中有一个用户表,也有一个管理表。 when i create new project using built-in mvc template it provide controller (which are really great) uses its own DB. 当我使用内置的mvc模板创建新项目时,它提供的控制器(确实很棒)使用其自己的数据库。

1) i want to store the registered user information in my DB and also login them not with the default DB Context 2) i have 2 tables (Users, Admin) now how can i use role manager on both tables ? 1)我想将注册的用户信息存储在我的数据库中,并且也不要使用默认的数据库上下文登录它们。2)我有2个表(Users,Admin),现在我如何在两个表上使用角色管理器? should i put Admin's table ID in auto created tables (aspnetroles, aspnetcalims, aspnetuserroles) or should i make only 1 table of name USERS and manage roles ? 我应该将Admin的表ID放入自动创建的表(aspnetroles,aspnetcalims,aspnetuserroles)中,还是只制作1个名称为USERS的表并管理角色?

sorry for my english. 对不起我的英语不好。

You can use default User table for all users since you have roles to differentiate them. 您可以对所有用户使用默认用户表,因为您具有区分它们的角色。 Creating another table for users in an admin role will just add nearly identical table to maintain. 为具有管理员角色的用户创建另一个表只会添加几乎相同的表进行维护。

If you want to use your own DB context, you can derive it from IdentityDbContext<TUser> or IdentityDbContext<TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim> instead of DbContext and then use it for identity as well. 如果要使用自己的数据库上下文,则可以从IdentityDbContext<TUser>IdentityDbContext<TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>而不是DbContext ,然后也将其用于标识。

You can further customize ASP.NET Identity schema by extending it's entity classes such as IdentityUser. 您可以通过扩展它的实体类(例如IdentityUser)来进一步自定义ASP.NET身份模式。

class MyUser : IdentityUser
{
    public string MyColumn { get; set; }
}

For more control, you can extend IdentityUser<TKey, TLogin, TRole, TClaim> to specify types for keys other than string(uniqueidentifier), custom entities for roles, etc. 为了获得更多控制,您可以扩展IdentityUser<TKey, TLogin, TRole, TClaim>以指定除字符串(uniqueidentifier)以外的键类型,角色的自定义实体等。

You can map default identity entities to a custom table as with any other EF entities using Fluent API by overriding OnModelCreating of your DB context and using DbModelBuilder . 与Fluent API OnModelCreating ,您可以通过覆盖数据库上下文的DbModelBuilder并使用DbModelBuilder来将默认标识实体映射到自定义表,就像其他任何EF实体DbModelBuilder

eg 例如

modelBuilder.Entity<ApplicationUser>().ToTable("MyUsers");

ASP.NET Identity is very customizable. ASP.NET Identity是非常可定制的。 You should not have any problems extending it, if you are familiar with Entity Framework. 如果您熟悉实体框架,则扩展它应该没有任何问题。

Some basic examples: http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx 一些基本示例: http : //blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM