Skip to main content

Access the Security System in Code

  • 2 minutes to read

This lesson will guide you through using the SecurityStrategy class to check whether or not a user has particular permission. The SetTask Action will be accessible to users who have permission to modify DemoTask objects.



Before proceeding, we recommend that you review the following lessons:

  • Open the TaskActionsController.cs (TaskActionsController.vb) file you created in the Add an Action with Option Selection lesson. Add the “using” directive and modify the Activated event handler as shown below.

    using DevExpress.ExpressApp.Security;
    public partial class TaskActionsController : ViewController {
        // ...
        private void TaskActionsController_Activated(object sender, EventArgs e) {
            View.SelectionChanged += View_SelectionChanged;
        void View_SelectionChanged(object sender, EventArgs e) {
        private void UpdateSetTaskActionState() {
            bool isGranted = true;
            SecurityStrategy security = Application.GetSecurityStrategy();
            foreach(object selectedObject in View.SelectedObjects) {
                bool isPriorityGranted = security.CanWrite(selectedObject, nameof(DemoTask.Priority));
                bool isStatusGranted = security.CanWrite(selectedObject, nameof(DemoTask.Status));
                if(!isPriorityGranted || !isStatusGranted) {
                    isGranted = false;
            SetTaskAction.Enabled.SetItemValue("SecurityAllowance", isGranted);

    With the added code, the Set Task Action will be activated for users who have write permissions for the Priority and Status properties of the selected DemoTask objects.

  • Add a user who does not have permission to modify the DemoTask objects (see Using the Security System). Run the application as this new user. The Set Task Action will not be visible when you display the Demo Task List View.


This is the last lesson of the In-Depth Tutorial. To learn how to deploy XAF applications, review the Deployment Tutorial.

See Also