Skip to main content

Access Rules

  • 3 minutes to read

This topic illustrates how to define security permissions for folders and files using a set of folder/file access rules (the FileManagerSettingsPermissions.AccessRules collection). Indexing rules within a collection allows you to control the rules’ priority. A rule with a higher index has a higher priority.

Note

Refer to the Permissions topic for details on how to permit or deny access to individual files and folders or to implement complicated user access logic.

To set up access rules for folders (including their files and child folders) and individual files, use the FileManagerFolderAccessRule and FileManagerFileAccessRule elements. The table below lists the access rule properties that are available for files and folders.

Rule Properties File Access Rule Folder Access Rule Description
Path - + A path to which the rule is applied
Path Pattern + - A pattern for file paths to which an access rule is applied.
Role + + A role to which the rule is applied
Browse - + Permission to view a file/folder
Full Access + - Full access permission for files
Download + - Permission to download a file
Edit + + Permission to edit files/folders
Edit Content - + Permission to edit folder content (files within a folder)
Upload - + Permission to upload files to a folder

The following Rights enumeration values determine permissions:

Value Description
Allow Rights.Allow The action is allowed within the access rule.
Deny Rights.Deny The action is denied within the access rule.
Default Rights.Default The action has an identical permission as the current item (file or folder) parent element. It corresponds to the Rights.Allow permission if this value does not exist.

Associating any number of access rules with specific security roles allows you to group related permissions. To associate an access rule with a security role, assign the role’s name to the rule’s Role property. Related access rules should be assigned to matching role names.

Use the FileManagerSettingsPermissions.Role property to enforce any created role on the FileManager. After that, the file manager displays folders and files and provides access permissions to them based on the assigned role.

Note

Online Demo

FileManager - Access Control

Examples

How to deny editing files except JPG files:

@Html.DevExpress().FileManager(
    settings => {
        settings.Name = "fileManager";
        ...
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFileAccessRule { PathPattern = "*.jpg", Edit = Rights.Allow });
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFileAccessRule { PathPattern = "*", Edit = Rights.Deny });
    }
).BindToFolder(Model).GetHtml()

How to deny browsing the ‘Admin’ folder:

@Html.DevExpress().FileManager(
    settings => {
        settings.Name = "fileManager";
        ...
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFolderAccessRule { Path = "Admin", Browse = Rights.Deny });        
    }
).BindToFolder(Model).GetHtml()

How to deny editing the ‘ReadOnly’ folder:

@Html.DevExpress().FileManager(
    settings => {
        settings.Name = "fileManager";
        ...
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFolderAccessRule { Path = "ReadOnly", Edit = Rights.Deny });
    }
).BindToFolder(Model).GetHtml()

How to deny uploading any folders except ‘UploadFolder’ folder:

@Html.DevExpress().FileManager(
    settings => {
        settings.Name = "fileManager";
        ...
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFolderAccessRule { Path = "", Upload = Rights.Deny });
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFolderAccessRule { Path = "UploadFolder", Upload = Rights.Allow });
    }
).BindToFolder(Model).GetHtml()

How to deny non-admin users permission to edit files:

@Html.DevExpress().FileManager(
    settings => {
        settings.Name = "fileManager";
        ...
        settings.SettingsPermissions.Role = User.IsAdmin ? "Admin" : string.Empty;
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFolderAccessRule { Path = "", Edit = Rights.Deny });
        settings.SettingsPermissions.AccessRules.Add(new FileManagerFolderAccessRule { Path = "", Edit = Rights.Allow, Role = "Admin" }); 
    }
).BindToFolder(Model).GetHtml()