认证 – asp.net mvc 3:Page.User.IsInRole(“xy”)返回null

我迁移了一个mvc 2应用程序到版本3.

不幸的是,在我的部分登录文件中,用户登录时会抛出异常.Request.IsAuthenticated返回true,但Page.User返回null!

而且当然

Page.User.IsInRole( “XY”)

抛出异常:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法对空引用执行运行时绑定

如何使用Razor检查用户角色?

解决方法

通过查看认的mvc3项目找到解决方案:
Context.User.IsInRole("xy")

而不是Page.User.IsInRole(“xy”)

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...