开发者

asp.net mvc 3: Page.User.IsInRole("xy") returns null

开发者 https://www.devze.com 2023-02-17 11:01 出处:网络
I migrated an mvc 2 app to version 3. Unfortunatly in my partial logon file, an exception is th开发者_如何学Gorown when the user is logged in. The Request.IsAuthenticated returns true, but the Page.U

I migrated an mvc 2 app to version 3.

Unfortunatly in my partial logon file, an exception is th开发者_如何学Gorown when the user is logged in. The Request.IsAuthenticated returns true, but the Page.User returns null!

And of course

Page.User.IsInRole("xy")

throws an exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference

How do I check the user role with Razor?


Found the solutions by looking at a default mvc3 project:

Context.User.IsInRole("xy")

instead of Page.User.IsInRole("xy")

0

精彩评论

暂无评论...
验证码 换一张
取 消