Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

IdentityRole is not part of the model for the current context when extending IdentityRole

$
0
0

Hello,

I have just extended my IdentityRole following this tutorial: http://johnatten.com/2014/06/22/asp-net-identity-2-0-customizing-users-and-roles/

    public class ApplicationRole : IdentityRole    {        public ApplicationRole() : base() { }        public ApplicationRole(string name) : base(name) { }        public String ApplicationId { getset; }        public AspNetApplications Application { getset; }    }

I have also updated my RoleManager in my IdentityConfig file like this:

    public class ApplicationRoleManager : RoleManager<ApplicationRole>    {        public ApplicationRoleManager(            IRoleStore<ApplicationRolestring> roleStore)            : base(roleStore)        {        }        public static ApplicationRoleManager Create(            IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context)        {            return new ApplicationRoleManager(                new RoleStore<ApplicationRole>(context.Get<ApplicationDbContext>()));        }    }

However, the issue starts when I try to Seed my data, I get this error: IdentityRole is not part of the model for the current context 

Also, when I try to login to my application, it shows that this line is giving out the error: 

var userIdentity = await manager.CreateIdentityAsync(thisDefaultAuthenticationTypes.ApplicationCookie);

I'm quite confused as to what I need to do properly to add one column to my AspNetRoles table and actually get data from it. E.g.

List<ApplicationRole> data = (from ar in dbContext.Roles    join a in dbContext.AspNetApplications    on ar.ApplicationId equals a.Id    select new ApplicationRole    {         Id = ar.Id,         ApplicationId = ar.ApplicationId,         Name = ar.Name    }).ToList();

I'm using ASP.NET MVC5. Hope someone can help with this. I've tried this for several days now.


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>