I have ASP.NET MVC 4 application. I use Simple Membership Provider allowing to tick remember me checkbox under login form. If ticked, persitent cookie .ASPXAUTH is created which expires 100 days from login date. And everything works fine, apart of main menu of the application.
Some parts of the menu are available for admin users only. I use:
@if (User.IsInRole("Administrator")) { @Html.Partial("_MainMenuPartial") }
to lock them from being rendered for regular user. This approach works fine just after logging into the system. When I return after a while and persistent cookie is used to authenticate me, I do get logged in, but
@User.IsInRole("Administrator")
returns "False" so I can't see admin menu items. At the same time
@User.Identity.Name
returns proper login name and
@User.Identity.IsAuthenticated
returns "True", what proves that persistent cookie works fine. Why can't I access user roles even though user is authenticated by the system then?
Websecurity.InitialiseDatabaseConnection
useif (!Roles.RoleExists("Admin")) Roles.CreateRole("Admin");
. Did you try and use the overloaded method I described in my answer. – Fivespot