问题描述
我有几个问题.我有一个带有identityserver4和EF的asp.net核心应用程序的安装程序.效果很好.现在我想知道我必须以哪种方式将项目存储在数据库中.
i have a few questions. I have a setup with an asp.net core application with identityserver4 and EF. that works fine. Now i want to know which way i have to store items in the database.
我有七个用于身份数据库的表:
i have seven tables for identity database:
AspNetUSerRoleClaims - claims for roles (which roles has access to what)
AspNetRoles - roles of the user
AspNetUserClaims - claims of the user like firstname, country
AspNetUserLogins - how to use this table?
AspNetUserRoles - roles for users
AspNetUsers - user stored here
AspNetUserTokens - how to use this table
现在,我已经在数据库中注册了一个用户和一些角色,并将连接设置为AspNetUserRoles(具有该角色的用户).现在,我想通过国家/地区,gived_name,family_name之类的注册向用户添加更多信息.但是我必须将它们存储在哪里.
Now i have registered a user and a few roles in the database and set the connection to the AspNetUserRoles (which role has the user).Now i want to add more information to the user through the registration like country, given_name, family_name. But where i have to store them. only in the AspNetUserClaims or should i store the information in the AspNetUser table (through ApplicationUser and a extra column in the AspNetUser table)?
我如何将项目存储在AspNetLogin和AspNetToken表中,还是由Identityserver自动完成?
And how can i store items in the AspNetLogin and AspNetToken table or is this automatically done by the Identityserver?
预先感谢您的回答
推荐答案
我有一个类似的问题,并发布了相关文章.
I have a similar problem and have posted a related article.
我能说的是这个...
What I can say is this ...
- AspNet *表是为普通的AspNet身份验证创建的(即,如果您不使用其他身份验证机制或自定义用户存储)
- 如果要将列添加到AspNetUsers表,则扩展IdentityUser类. (例如,公共类MyApplicationUser:IdentityUser),然后添加您的自定义属性(例如,FirstName).这实质上改变了模型.为了确保EF将模型更改写入数据库表,您需要使用新的MyApplicationUser类扩展IdentityDbContext类.
- 如果要将用户的自定义声明(例如hair_color)添加到AspNetUserClaims表中,则需要调用userManager.AddClaimAsync().您可以在注册过程或登录过程中使用表单中的数据,或从外部身份验证提供商(例如Google,Facebook,Twitter等)收到的声明中进行此操作.
- 通常,如果您使用的是IdentityServer,则不使用AspNetUserTokens表,因为IDS的主要职责是发行和验证令牌(id_tokens,access_tokens等)
希望这可以帮助您入门.
Hope this helps getting you started.
我正在尝试确定最佳实践是将其他用户信息添加到实体(即AspNetUsers)还是将其添加为AspNetUserClaims中的声明.
I'm trying to figure out if its best practice to add additional user information to the entity (ie AspNetUsers) or to add them as claims in AspNetUserClaims.
这篇关于具有identityserver4的ASP.Net Core MVC身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!