entity framework - How to customize ASP.NET Identity to handle users scoped within applications? -



entity framework - How to customize ASP.NET Identity to handle users scoped within applications? -

i working on application records users registers access resources on web pages. i'm using asp.net mvc 5 asp.net identity. utilize same value email , username. have table store webpages. added webpageid column aspnetusers table identify webpage. actually, between aspnetusers table , webpage table there many many relationship, reason wanted have multiple records user in aspnetusers table – 1 each webpage user registered.

if user user@examplemail.com registered webpage1 not mean registered webpage2. when registers webpage2 same e-mail should invisible him registered in scheme user of webpage1.

in order have multiple records same username in aspnetusers table removed unique index on username , instead i created unique index on 2 columns: username , webpageid.

but when seek register webpage2 e-mail address registered webpage1, dbentityvalidationexception next validation message : „username user@examplemail.com has been taken”. thrown in accountcontroler.register() method when usermanger used create new user.

my first seek solve problem customize usermanager class. created subclass of usermanager overriden findbyemailasync , findbynameasync methods in way pair email+webpage or name+webpage:

var existinguser = this.db.users .firstordefault(x => x.username == username &&  x.webpageid == webpageid); return existinguser;

my sec seek additionally customize uservalidator of usermanager. there similar code above - seek user same username , webpageid. when user not found, homecoming identityresult.success.

no success. still having dbentityvalidationexception „username user@examplemail.com has been taken” validation error.

any thought asp.net identity component still looks user user name (without checking webpageid)? how should customize asp.net identity handle such scenario?

here part of exception callstack:

at system.data.entity.internal.internalcontext.savechangesasync(cancellationtoken cancellationtoken) @ system.data.entity.internal.lazyinternalcontext.savechangesasync(cancellationtoken cancellationtoken) @ system.data.entity.dbcontext.savechangesasync(cancellationtoken cancellationtoken) @ system.data.entity.dbcontext.savechangesasync() @ microsoft.aspnet.identity.entityframework.userstore6.<savechanges>d__31.movenext() (...) @ system.runtime.compilerservices.taskawaiter1.getresult() @ userregistrationsystem.web.controllers.accountcontroller.d__11.movenext() in i:\repo\registrationsystem\userregistrationsystem.web\controllers\accountcontroller.cs:line 126

fyi, asked same question on asp.net identity forum.

what you're describing sounds multi-tenancy.

i've answered related question here, , provided library implement it

https://github.com/jskimming/aspnet.identity.entityframework.multitenant

asp.net-mvc entity-framework entity-framework-6 asp.net-identity asp.net-identity-2

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -