Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User.IsInRole doesn't work

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?

like image 513
Bartosz Avatar asked Mar 22 '13 09:03

Bartosz


1 Answers

I had a smilar issue. In my case the problem solved when i log off and log in again.

like image 70
Cem Mutlu Avatar answered Sep 23 '22 00:09

Cem Mutlu