Question

I am using code first with Entity Framework 6 and MVC 5.1 in Visual Studio 2013. Without making any changes to the web.config, model classes, or anything directly relating to Roles my app lost the ability to determine a User's Role membership. In fact most of the project is boilerplate MVC. I was purposefully trying to keep it as simple as possible. Nothing fancy.

Authentication works and System.Web.HttpContext.Current.User.Identity is populated appropriately.

Outputting string.Join(",", Roles.GetRolesForUser()) shows that the user, though logged in, belongs to no roles.

Double checking the AspNetRoles, AspNetUsers, and AspNetUserRoles shows that the user is associated with a number of different roles.

Not more than 24 hours ago all role specific features were working appropriately so I at least know that everything had been correctly configured at some point.

Short of posting my entire project it is impossible to list all the factors but I was hoping others may have had a similar experience and provide possible solutions.

Was it helpful?

Solution

it looks like the Code First role provider needs lazy-loading enabled. I had disabled lazy-loading earlier. base.Configuration.LazyLoadingEnabled = false;. The role provider began working as soon as I enabled this feature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top