User.IsInRole不起作用 [英] User.IsInRole doesn't work

查看:230
本文介绍了User.IsInRole不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ASP.NET MVC应用4。我用简单的成员资格提供允许打勾记得我在登录表单复选框。如果勾选,persitent饼干.ASPXAUTH创建这将过期登录日期100天。 ,一切工作正常,除了应用程序的主菜单。

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") }

从正在呈现为普通用户锁定他们。这种做法只是登录到系统后,工作正常。当我一会永久性Cookie后返回来验证我的,我做得到登录,但

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

返回True,有什么证明,持久性cookie正常工作。为什么我不能访问用户角色,即使用户被系统验证呢?

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?

推荐答案

我有一个smilar问题。在我的情况下,问题解决了,当我注销并重新登录。

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

这篇关于User.IsInRole不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆