Use ASP.NET Identity on existing DB-Model PART 1

codingfreaks · 85K views · 2014 · 49:32

Open on YouTube

Web developmentDatabases & storagetutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when someone needs to run ASP.NET Identity on top of an existing or legacy database instead of the default generated schema.

Recommended by 5 people across 5 different months, 2014 to 2017.

What it is

A 49-minute screencast by Alexander Schmidt (codingfreaks) showing how to bring ASP.NET Identity into an existing project that already has its own database model. It is a hands-on walkthrough that accompanies his blog article with source code, and it is the first of two parts.

What people said

Recommends Mike Stone · 2014-02 · Stack Overflow · on “ASP.Net Identity with WebForms to existing SQL database”

We decided that since we would be creating a new database that we would just follow the code-first approach. For those interested I found this Use ASP.NET Identity on existing DB-Model [this video] and it is VERY good. I tried following it but got stuck right at the end and didn't want to spend a lot of time on it since CF was decided. Thanks for the help

Recommends Rich Freeman · 2014-03 · Stack Overflow · on “ASP.NET/Identity Error: The entity type ApplicationUser is not part of the model for the current context”

(INELEGANT?) SOLUTION: I watched this excellent video [this video] by Alexander Schmidt and at 33:00 the author reveals that the connection string should not be an EF connection string (using the EF provider) but should be a vanilla MYSQL/SQLServer connection string specifically set up for security, ie: <add name="IMSSecurityEntities" connectionString="data source=localhost;database=mydb;Uid=id;Pwd=password;" providerName="mysql.data.mysqlclient"/> and similarly the identity model should be adjusted to: Public Class ApplicationDbContext Inherits IdentityDbContext(Of ApplicationUser) Public Sub New() MyBase.New("IMSSecurityEntities") End Sub This makes me nervous about accessing the security entit

Recommends DSR · 2014-09 · Stack Overflow · on “Extending IdentityUserRole in Identity 2.0”

Take a look at below video tutorial on using asp.net identity using existing database tables. I think you have to let ApplicationUser table know that you have new field in your ApplicationUserRole table. So that you have to follow entity framework model binding in order to achieve that. Part 1 - [this video] Part 2 - [LINK] You don't need to implement your own userManager, but you have to amend it. Hope you can use this example to support your needs.

Recommends DSR · 2014-09 · Stack Overflow · on “Merge MyDbContext to Asp.net IdentityDbContext”

If I got you correct, you are trying to use your existing database, tables and existing users with asp.net identity framework. First thing, according to my understanding, you can't merge your db context (MyDbContext) with 'IdentityDbContext', because context of asp.net identity framework tables has to be inherited from IdentityDbContext<YourUserTable> . But your other tables may inherited from DbContext . Therefore you have to use two separate db contexts if you want to use identity framework build in method support, which is UserManager etc. You can use your existing database with identity framework, you just need to correctly bind your database tables with identity framework EF code first

Recommends DSR · 2014-09 · Stack Overflow · on “Upgrading SQL authentication EF database first to Identity 2”

There is a YouTube video tutorial which may help you to get some idea in order to achieve your task. Actually this isn't for migrating membership to Identity 2.0, but this video illustrates to use Identity 2.0 with existing database. I hope you can work with your current resources (The given link). Part 1: [this video] Part 2: [LINK] Hope this helps.

Recommends C-JARP · 2015-04 · Stack Overflow · on “Using ASP.NET 5, Identity 2 with custom store and roles with permissions”

There is that possibility ofcourse. What you are looking for is a way to have the identity 2 mechanics but use your own mapping. You can look at this question for answers: ASP.NET Identity User and Roles in Multisite [LINK] and the following video shows you some info about using existing Db's with identity 2: [this video] I did something similar but for multitenancy purposes. The concept i used was explained in an earlier question i did: Middleware for multisite ASP.NET Identity 2 [LINK] To be precise, there is no out of the box system that you can use, but Identity 2 is very customizable. In order for you to have your own tables, you have to create a custom DbContext or override the IdentityDbCo

Recommends user1347295 · 2015-05 · Stack Overflow · on “ASP.net MVC 5 : Extend IdentityUser class to use My User Entity Class”

Are you overriding OnModelCreating Class? Sample: protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); //Map Entities to their tables. modelBuilder.Entity<ApplicationUser>().ToTable("MyUser"); } you should let entity framework know that for MyUser Entity ApplicationUser entity should be used. This link was very helpful for me : [this video]

Cites Alexander Schmidt · 2014-01 · Stack Overflow · on “Custom Implementation of Microsoft.AspNet.Identity.IUser”

I found out that starting with ASP.NET Identity 2 (still in prerelease) you can do: public class MyUser : IdentityUser<long> Its a little bit more than that when it comes to real life. I blogged about it at codingfreaks [LINK] (German) and added an English Screencast at [this video] . You can find some good hints here [LINK] . So, it is possible.

Cites Lars · 2014-11 · Stack Overflow · on “Inherit from IdentityUser I get an error on UserManager<User>”

When you extend with your own User class you have to provide all of the types that Identity uses. Here is my context class, notice that i use string as key: public class EarlyDetectionContext : IdentityDbContext<User, Role, string, EDLogin, RoleUserAssociation, EDClaim> Of course you also need to make classes for role userlogin, userclaim and userroles. Here is mine: public class EDClaim : IdentityUserClaim<string> { } public class EDLogin : IdentityUserLogin<string> { } [Table("Roles", Schema = "ED")] public class Role : IdentityRole<string, RoleUserAssociation> { [Required, Column("DisplayName")] public string DisplayName { get; set; } [Required, Column("Created")] public DateTime Created

Cites user5709087 · 2016-03 · Stack Overflow · on “How to generate EDMX file for EF6 in ASP.Net5 (Database first approach)”

there are some tutorials that you can see in youtube : ASP.NET MVC 5 Step by Step: Part 5 Entity Framework Database First [LINK] Use ASP.NET Identity on existing DB-Model PART 1 [this video] and this is one sample [LINK] of integration asp.net identity and EF Db First that I developed 2 years ago you can use following method for generate .EDMX file in code first approach: void ExportMappings(DbContext context, string edmxFile) { var settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(edmxFile, settings)) { System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(context, writer); } } if your database is already then you can use Entity Framework Power Tools