Condition statement based on user roles

Feb 9, 2011 at 9:12 PM
Edited Feb 9, 2011 at 9:26 PM
Can some one please show me an inline if statement code example using blogengine membership roles. I have a separate CSS menu which I want to display certain links based on whether your anon, editor or admin. E.g. If userRole=administrator then Print ' li' Else print 'no access'. Thanks
Coordinator
Feb 10, 2011 at 12:23 AM

To check if logged in: Security.IsAuthenticated

To check for specific right: Security.IsAuthorizedTo(Rights.AccessAdminPages)

etc.

public enum Rights
    {
        None = 0,
        ViewDetailedErrorMessages,
        AccessAdminPages,
        AccessAdminSettingsPages,
        ManageWidgets,
        ViewPublicComments,
        ViewUnmoderatedComments,
        CreateComments,
        ModerateComments,
        ViewPublicPosts,
        ViewUnpublishedPosts,
        CreateNewPosts,
        EditOwnPosts,
        EditOtherUsersPosts,
        DeleteOwnPosts,
        DeleteOtherUsersPosts,
        PublishOwnPosts,
        PublishOtherUsersPosts,
        ViewPublicPages,
        ViewUnpublishedPages,
        CreateNewPages,
        EditOwnPages,
        EditOtherUsersPages,
        DeleteOwnPages,
        DeleteOtherUsersPages,
        PublishOwnPages,
        PublishOtherUsersPages,
        ViewRatingsOnPosts,
        SubmitRatingsOnPosts,
        ViewRoles,
        CreateNewRoles,
        EditRoles,
        DeleteRoles,
        EditOwnRoles,
        EditOtherUsersRoles,
        CreateNewUsers,
        DeleteUserSelf,
        DeleteUsersOtherThanSelf,
        EditOwnUser,
        EditOtherUsers,
    }

Feb 10, 2011 at 9:50 AM

Hi rtur,

Thanks for your response, however I was more specifically after a condition statement which checked for the role the user had logged in with.

E.g.

<% if (User.IsInRole("admininistrator")) { %>
  You can see this snippet of HTML
<% } else { %> You don't see anything
<%} %>

 

Thanks

Mar 3, 2011 at 12:34 PM

Hi,

Can anyone shed some light on the following, I just want a simple condition statement that displays specific content based on whether your logged in as an Editor or Administrator.

I can't quite figure out the method I should be calling in the if statement.

Thanks 

Mar 3, 2011 at 6:37 PM

You can do something like :

 if (Security.IsAuthenticated && Security.IsAdministrator ){}

else {}

Also, there is something like Security.IsSystemRole(string rolename) where rolename can be editor, anonymous and administrator). I hope this helps.

 

 

Mar 3, 2011 at 7:48 PM

Ajexpress that worked a treat!

 

Thanks