c# - How to implement ASP.NET Identity 2.0 in existing database? -


i'm having existing membership implemented in asp.net 4.5 web forms project. application uses entityframework 6.1.3 version dbcontext , in database first approach. want migrate old membership use new asp.net identity 2.0 system.

i have followed this article performing migration never succeeded. got errors mentioned in the property 'claims' on type 'aspnetuser' not navigation property.

it confirms i'm missing basic in migration process.

can provide me step step guide perform success migration?

i want address following points:

1) in identity, have user data other default identity providing. see there identitycontext these identity operations. have different context inherits dbcontext. need use both contexts? in other words identitycontext compulsory identity operation? cannot these 2 contexts merged one?

2) i'm not restricted database first approach. since identity uses code first approach okay go ahead code-first approach needs correct steps follow up.

3) since have user data need extend identityuser add new properties? if extend identityuser identity code work seamlessly?

4) followed https://www.youtube.com/watch?v=blmkpa7xqf8 video tutorial adds migration in applicationdbcontext. applicationdbcontext inherits identitycontext. worked me want add migration own context inherits dbcontext. it's because applicationdbcontext doesn't include other tables(non-identity tables).

5) tried applying migration in custom context.cs file contains identity , non-identity tables. created class using reverse engineering approach entityframework power tools suggested in this article.

after poco classes created, added migration , updated database. main errors got are:

identityuserlogins: entitytype: entityset 'identityuserlogins' based on type 'identityuserlogin' has no keys defined.   identityuserroles: entitytype: entityset 'identityuserroles' based on type 'identityuserrole' has no keys defined. 

as per solution added configuration ended creating new tables identityuserlogin, identityrole etc. duplicate identity tables.

6) if i'm keeping duplicate identity tables (e.g aspnetuserroles , identityuserrole), i'm not able fetch data using identity code var user = usermanager.findasync(username.text, password.text); , getting exception:

invalid column name 'userid' 

1) in identity, have user data other default identity providing. see there identitycontext these identity operations. have different context inherits dbcontext. need use both contexts? in other words identitycontext compulsory identity operation? cannot these 2 contexts merged one?

yes, need use 2 context when implements asp.net identity database first. asp.net identity uses system.data.sqlclient provider while edmx uses system.data.entityclientprovider.

2) i'm not restricted database first approach. since identity uses code first approach okay go ahead code-first approach needs correct steps follow up.

it easy implement in code first approach asp.net mvc default template provides implementation of asp.net identity code first approach not problem database first approach well. https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/

3) since have user data need extend identityuser add new properties? if extend identityuser identity code work seamlessly?

yeah, can extend it.whenever want extend properties of user.identity additional properties , add these properties applicationuser class first so:

public class applicationuser : identityuser     {         public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager)         {             // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype             var useridentity = await manager.createidentityasync(this, defaultauthenticationtypes.applicationcookie);             // add custom user claims here             return useridentity;         }          //extended properties         public string city { get; set; }     } 

these 3 points resolve remaining points well.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -