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.v24.1.dll
NuGet Package: DevExpress.ExpressApp.Security
Declaration
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 Core 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.