The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
The page you are viewing does not exist in the .NET Standard 2.0+ platform documentation. This link will take you to the parent topic of the current section.
.NET Core 3.0+
The page you are viewing does not exist in the .NET Core 3.0+ platform documentation. This link will take you to the parent topic of the current section.

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.v19.2.dll

Declaration

public static bool IsUserInRole(
    this IUserWithRoles user,
    string roleName
)
<ExtensionAttribute>
Public Shared Function IsUserInRole(
    user As IUserWithRoles,
    roleName As String
) As Boolean

Parameters

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).

Returns

Type Description
Boolean

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

Remarks

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() {
        base.OnActivated();
        ISecurityUserWithRoles currentUser = (ISecurityUserWithRoles)SecuritySystem.CurrentUser;
        restrictedAction.Enabled["ForAdminsOnly"] = currentUser.IsUserInRole("Administrators");
    }
    // ...
}
Important

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