简体   繁体   English

使用实体框架将asp.net Identity实现到现有数据库中

[英]Implementing asp.net Identity into already existing database with entity framework

I am trying to update an older website. 我正在尝试更新旧网站。 It already has an existing database with a user and a role table, with existing data in it. 它已经有一个包含用户和角色表的现有数据库,其中包含现有数据。

I need to create a new web-api and a new web project and integrate ASP.NET Identity into the already existing database. 我需要创建一个新的web-api和一个新的Web项目,并将ASP.NET Identity集成到现有的数据库中。

I have currently setup my solution to breakup the projects as follows: 我目前正在设置解决方案以解决项目,如下所示:

  • Domain
  • Services 服务
  • WEB_API WEB_API
  • WEB_UI WEB_UI

My aim is to implement the Identity in the services layer so that both my WebAPI and MVC site can utilize the same identity mechanism. 我的目标是在服务层实现Identity,以便我的WebAPI和MVC站点都可以使用相同的身份机制。

I am fairly overwhelmed at the moment, I have read many tutorials and articles over the last day or two and have ended up with the options of either re-implementing the IUserStore and IRoleStore . 我现在相当不知所措,我在过去一两天内阅读了许多教程和文章,并最终选择了重新实现IUserStoreIRoleStore And also with mapping the different entities in the OnModelCreatingMethod . 并且还可以映射OnModelCreatingMethod的不同实体。

I cant seem to find a tutorial which is aimed at what I want to do. 我似乎找不到针对我想做的教程。 My database is to different to simply remap the names of columns, And I dont want to re-implement the entire Identity Stores as there are only a few conflicting fields. 我的数据库不同于简单地重新映射列的名称,而且我不想重新实现整个Identity Stores,因为只有少数冲突的字段。 Most tuts I have found are related to using mysql instead of EF. 我发现的大部分内容都与使用mysql而不是EF有关。 I still want to make use Entity Framework. 我还是想使用Entity Framework。

Issues I have: 我遇到的问题:

  • The current Users Table in the database used Int pk , not GUID 数据库中的当前Users Table使用Int pk,而不是GUID
  • The Password Field uses a different Hashing algorithm. 密码字段使用不同的哈希算法。 So i would need to override how Identity checks and store the password. 所以我需要覆盖Identity检查和存储密码的方式。
  • I do not have all the required Identity User fields in my database, however I am able to add new fields, I just cant change already existing fields. 我的数据库中没有所有必需的Identity User字段,但是我能够添加新字段,我只是无法更改现有字段。
  • I am making use of Database First as the DB already exists. 我正在使用Database First,因为数据库已经存在。

So basically my question is, In what direction do I need to go in order to overcome the above mentioned issues. 所以基本上我的问题是,为了克服上述问题,我需要朝哪个方向前进。 Can I get away with changing the Database mapping? 我可以通过更改数据库映射来逃脱吗? Or do I need to go as far as re implementing the User and Role Stores? 或者我是否需要重新实现用户和角色存储?

What I had initially planned was to re-implement the User and Role Stores using entity framework, And i could then make use if the DB first model classes and map the actual DB structure and fields to my ApplicationUser Fields. 我最初计划的是使用实体框架重新实现用户和角色存储,然后我可以使用,如果数据库首先建模类并将实际的数据库结构和字段映射到我的ApplicationUser字段。 But this is where I thought I might be diving into cold waters, and i'm generally not a fan of reinventing the wheel if not necessary. 但这就是我认为我可能潜入寒冷水域的地方,如果没有必要,我通常不会重新发明轮子。

-The first thing you should do if you haven't already is to BACK-UP your current database! - 如果您还没有备份当前数据库,首先应该做的事情!

You could use code first to update an existing database. 您可以首先使用代码来更新现有数据库。

I found this walkthrough and it seemed close to the route you're on, and I'm hoping it will help solve your problem, begin at "Migrating to Visual Studio 2013". 我找到了这个演练,它似乎接近你所在的路线,我希望它有助于解决你的问题,从“迁移到Visual Studio 2013”​​开始。 http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity

This would create a few new tables, but not necessarily a new database. 这将创建一些新表,但不一定是新数据库。

Download Nuget packages: Microsoft.AspNet.Identity.EntityFramework, Microsoft.AspNet.Identity.Owin, Microsoft.Owin.Host.SystemWeb 下载Nuget软件包:Microsoft.AspNet.Identity.EntityFramework,Microsoft.AspNet.Identity.Owin,Microsoft.Owin.Host.SystemWeb

Enable-migrations and run a script such as this: https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/SQLMembership-Identity-OWIN/Migrations.sql 启用迁移并运行如下脚本: https//aspnet.codeplex.com/SourceControl/latest#Samples/Identity/SQLMembership-Identity-OWIN/Migrations.sql

Or you could try using a reverse POCO generator found in visual studio extensions. 或者您可以尝试使用Visual Studio扩展中的反向POCO生成器。

(My 1st attempt at writing an answer here. Tried to clarify.) (我第一次尝试在这里写答案。试图澄清。)

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

相关问题 ASP.NET Identity 3.0实体框架数据库种子 - ASP.NET Identity 3.0 Entity Framework Database Seeding Blazor ASP.NET 托管身份验证,使用现有数据库和身份表 - Blazor ASP.NET Hosted Identity Authentication with already existing database with Identity tables 实体框架和ASP.NET标识 - Entity framework and ASP.NET Identity 没有实体框架的ASP.NET标识 - ASP.NET Identity without Entity Framework 将ASP.NET Identity集成到现有数据库 - Integrating ASP.NET Identity to existing database 身份模型中的实体框架ASP.NET MVC6,创建新记录,而不是将其链接到现有记录 - Entity Framework ASP.NET MVC6 in Identity Model, Creating a new record instead of linking it to existing record 使用现有的ASP.NET Identity提供程序实现Orchard的IMembershipService - Implementing orchard's IMembershipService with existing ASP.NET Identity provider 在现有的Web应用程序中实现ASP.NET Identity - Implementing ASP.NET Identity into existing web application 如何首先在ASP.NET MVC中将Identity与Entity Framework数据库一起使用 - How to use Identity with Entity Framework database first in ASP.NET MVC 具有自己的表定义的ASP.NET身份实体框架数据库第一种方法 - Asp.net identity entity framework database first approach with own table defintion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM