Using VS 2013, the standard MVC pattern and identity provider infrastructure
The user is logged in and I have:
//.... UserManager.AddToRole(User.Identity.GetUserId(), "Members"); # Line X RedirectToAction("Index", "Members");
And the member controller is as follows:
[Authorize(Roles="Members")] public class MembersController : Controller { // GET: Members public ActionResult Index() { return View(); } }
After running line X, I can confirm that the user has been added to the dbo.AspNetUserRoles table. However, the user does not check the role when it reaches the Member controller. User.IsInRole("Members") returns false.
If the user logs out and then logs back in, then access to the member controller will pass, i.e. User.IsInRole("Members") now returns true.
Is there any caching? Why is the delay? How to overcome it?
I also tried to convert the method in Line X to async method and used UserManager.AddToRoleAsync . The same deferred effect still exists.
asp.net-mvc asp.net-identity roleprovider
Old geezer
source share