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.2.dll
NuGet Package: DevExpress.ExpressApp.Security
#Declaration
#Parameters
Name | Type | Description |
---|---|---|
user | DevExpress. |
An IUser |
role |
String | A string that specifies the role name (see XPO Permission |
#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.