WebUser.IsInRole() Admin conflict issue

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/8/2010 7:28:29 AM
Gravatar
Total Posts 2

WebUser.IsInRole() Admin conflict issue

Hi,

I'v created two Roles "Captians" and "FirstOfficers"

I'm using the WebUser.IsInRole() to capture the logged in user in order to apply certain actions for each role.

So, I check using the following code

if (WebUser.IsInRole("Captains"))

//apply action related to Captains

else if (WebUser.IsInRole("FirstOfficers"))

//apply action related to First Officers

* That works fine, but when it come to administrators -there are some Captains that have "Admin Role" as well as "Captains Role", & there are some First Officers that have "Admin Role" as well as "FirstOfficers Role"- the code doesn't work properly, as the Portal behaves as if the logged in user has the first If Statement condition "even if the logged in user doesn't have the "Captains Role".

- That happens because the system considers that [The user that has the "Admin Role" has all the other Roles by default].

But I need to differentiate between the users that have "Captains Role" and "FisrtOfficers Role" "Even if they are administrators.

BTW, I tried IsInRoles("Captains"; "Administrators") is doesn't work it gives an error.

I also tried SiteUser.IsInRole("Captains") the same it doesn't work

Can anyone help my?

Thanks,

Andy

6/8/2010 7:42:10 AM
Gravatar
Total Posts 18439

Re: WebUser.IsInRole() Admin conflict issue

Hi Andy,

Those helper methods on WebUser always return true for Admins because there should be nothing that Admins cannot do, so no matter what roles are used to check permissions the admin always has permission.

Sounds like you are trying to use roles more like groups, so if you don't like logic of the WebUser helper class which is really designed for permission checks using roles not for group membership checks, you can always use the standard Context.User.IsInRole("rolename") to check specific role membership.

WebUser.IsInRoles does not take an array of strings, you have extra quotes there, it would use a single string with role names separated by semi colons and quotes only on either end of the string.

WebUser class is a helper for checking permissions of the current user against their role cookie, it does not access the db, so it is very efficient.

SiteUser.IsInRole is more expensive because it hits the db to check the user roles, but it can be used to check roles of a user who is not the currently logged in user.

Hope it helps,

Joe

6/8/2010 9:24:15 AM
Gravatar
Total Posts 2

Re: WebUser.IsInRole() Admin conflict issue

Hi Joe,

Thanks for the fast reply :)

I used the Context.User.IsInRole("rolename") , it works perfectly for my case, thanks a lot,

Regards,

Andy

You must sign in to post in the forums. This thread is closed to new posts.