Luk*_*lar 10 authentication c#-4.0 asp.net-mvc-3
我将mvc 2应用程序迁移到版本3.
不幸的是,在我的部分登录文件中,当用户登录时抛出异常.Request.IsAuthenticated返回true,但Page.User返回null!
而且当然
Page.User.IsInRole("xy")
抛出异常:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法对空引用执行运行时绑定
如何使用Razor检查用户角色?
Luk*_*lar 17
通过查看默认的mvc3项目找到解决方案:
Context.User.IsInRole("xy")
Run Code Online (Sandbox Code Playgroud)
而不是Page.User.IsInRole("xy")