Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I migrated an mvc 2 app to version 3.

Unfortunatly in my partial logon file, an exception is thrown 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?

like image 592
LukeSolar Avatar asked Mar 15 '11 15:03

LukeSolar


1 Answers

Found the solutions by looking at a default mvc3 project:

Context.User.IsInRole("xy")

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

like image 80
LukeSolar Avatar answered Oct 28 '22 10:10

LukeSolar