User.IsInRole doesn't work

后端 未结 16 1413
北恋
北恋 2020-12-05 18:29

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 w

16条回答
  •  难免孤独
    2020-12-05 19:05

    I had a similar problem with IsUserInRole returning false. By placing a watch on it, I was able to overcome the problem by using the overload described below. Try it, put a break point where you're getting false, and see what happens.

    @if (Roles.IsUserInRole(Model.UserName, "Administrator"))
    

    I'm pretty sure you could also use User.Identity.Name as the first parameter.

提交回复
热议问题