extend ASP.NET Core Identity user

前端 未结 2 1135
面向向阳花
面向向阳花 2021-01-26 01:45

Using structuremap for my DI. By default everything works, however I want to add fn and ln to AspNetUser DB. I\'ve added a new class like so:

public class Applic         


        
相关标签:
2条回答
  • 2021-01-26 02:14

    Thanks to @Jorge Rojas I was able to solve it. Not all references were replaced with ApplicationUser. In my Container I did not have to make any changes.

    0 讨论(0)
  • 2021-01-26 02:28

    To Striter:

    Is easy to miss an update to identity classes when creating subclases.

    So, the idea is:

    1) Check base clases you will override from identity: ApplicationUser, ApplicationRole, (if you modify it, not very common), ApplicationUserLogin, ApplicationClaims… etc. Note my example is taken from code I have where I modified UserRoles to include a company, so it's a bit more complex on the declaration.

    For example, you may have:

    public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
    { // Code… }
    

    Or (Not tested)

    public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, IdentityUserRole<int>, IdentityUserClaim<int>>
    { // Code… }
    

    Then replace them accord in all subroutines. In case of ShaneKm, he probably left that unchanged on DbContext or UserStore:

    public class ApplicationDbContext : IdentityDbContext<IdentityUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
    { // Code … }
    

    And fixed it like:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
    { // Code … }
    

    Fo search of missing replacements, right-click on "IdentityUser" in public class ApplicationUser : IdentityUser

    2) Sometimes you compile and not all things are updated, so old objs still refers to already changed code. Happens to me frequently with WCF. You have to clean obj and bin directories (I delete them) to ensure everything gets recompiled.

    Hope this clarifies.

    0 讨论(0)
提交回复
热议问题