A newer version of this page is available. Switch to the current version.

UserWithRolesExtensions.IsUserInRole(IUserWithRoles, String) Method

Static extension method that determines whether the user belongs to a specific role.

Namespace: DevExpress.ExpressApp.Security

Assembly: DevExpress.ExpressApp.Security.v18.2.dll


public static bool IsUserInRole(
    this IUserWithRoles user,
    string roleName


Name Type Description
user DevExpress.Persistent.Base.Security.IUserWithRoles

An IUserWithRoles object that specifies the user.

roleName String

A string that specifies the role name (see XPO PermissionPolicyRoleBase.Name or EF PermissionPolicyRoleBase.Name).


Type Description

true, if the user belongs to the given role; otherwise - false.


For example, you can use this method in a custom Controller to determine whether a user belongs to a certain role in code.

using DevExpress.ExpressApp.Security;
// ...
public class MyController : ViewController {
    // ...
    protected override void OnActivated() {
        ISecurityUserWithRoles currentUser = (ISecurityUserWithRoles)SecuritySystem.CurrentUser;
        restrictedAction.Enabled["ForAdminsOnly"] = currentUser.IsUserInRole("Administrators");
    // ...

Do not forget to add the using (Imports in VB) directive for the DevExpress.ExpressApp.Security namespace when using the IsUserInRole extension method.

See Also