User.IsInRole

User.IsInRole

Old forum URL: forums.lhotka.net/forums/t/2411.aspx


joel posted on Thursday, February 22, 2007

I'm having trouble getting my custom principal's IsInRole method to work in my web page's code behind.  Shouldn't I expect to be able to call User.IsInRole in a page's code behind?  I'm testing with the following in a page's load event...

Dim bln As Boolean = User.IsInRole("Web-View All Reports")

Response.Write("<br>User.IsInRole(""Web-View All Reports"") = " & bln.ToString)

I get false even though the custom principal loaded the role when it was fetched.

I notice the projecttracker application always relies on the business objects to check roles.  I see the logic in this, however I thought the reason we were implementing the custom principal was so both layers of the app could benefit from it?

I also get an InvalidCastException when I try this...

Dim MyPrincipal As VMIS.Business.Principal = User

Response.Write("<br>MyPrincipal.IsInRole(""Web-View All Reports"") = " & bln.ToString)

Did I code the identity, principal, login wrong, or are my expectations about how this works wrong?

Joel

 

RockfordLhotka replied on Thursday, February 22, 2007

Did you reload the principal in global.asax? The required code is shown in Chapter 10 of the 2005 book.

joel replied on Thursday, February 22, 2007

Thanks! That was it.

Joel

Copyright (c) Marimer LLC