Skip to main content

AccessSettings.TrySetRules(IAccessRule[]) Method

Sets resource access rules.

Namespace: DevExpress.Security.Resources

Assembly: DevExpress.Data.v24.1.dll

NuGet Package: DevExpress.Data

Declaration

public bool TrySetRules(
    params IAccessRule[] rules
)

Parameters

Name Type Description
rules IAccessRule[]

An array of access rules.

Returns

Type Description
Boolean

true, if the specified rule collection is registered successfully. Otherwise, false.

Remarks

Before you set access rules, specify the resources for which these rules should be checked. To do this, use one of the following static properties:

  • StaticResources

    // Images can be loaded only from the "C:\\StaticResources\\" file directory and "http://mysite.dev" site
      bool success = DevExpress.Security.Resources.AccessSettings.StaticResources.TrySetRules(
          DevExpress.Security.Resources.DirectoryAccessRule.Allow("C:\\StaticResources\\"),
          DevExpress.Security.Resources.UrlAccessRule.Allow("http://mysite.dev")) ;
      if (!success) System.Diagnostics.Debug.Print("Cannot change rules. The rules are already set.")
    
  • DataResources

    // JSON data can be loaded only from URLs; Excel data cannot be loaded from file directories (Excel data load from URLs is not supported)
      bool success = DevExpress.Security.Resources.AccessSettings.DataResources.TrySetRules(
          DevExpress.Security.Resources.UrlAccessRule.Allow(),
          DevExpress.Security.Resources.DirectoryAccessRule.Deny()) ;
      if (!success) System.Diagnostics.Debug.Print("Cannot change rules. The rules are already set.")
    
  • ReportingSpecificResources

    // Style sheets cannot be loaded from file directories; only XML report layout serialization format is allowed
      bool success = DevExpress.Security.Resources.AccessSettings.ReportingSpecificResources.TrySetRules(
          DevExpress.Security.Resources.DirectoryAccessRule.Deny(),
          DevExpress.Security.Resources.SerializationFormatRule.Deny(SerializationFormat.Xml)) ;
      if (!success) System.Diagnostics.Debug.Print("Cannot change rules. The rules are already set.")
    

The TrySetRules(IAccessRules[]) method can be called only once at runtime to prevent you from overriding rules. You should call this method when the application starts, before a control (Web End-User ReportDesigner) sets its own rules. Otherwise, the TrySetRules(IAccessRules[]) method does not register the specified rule collection and returns false.

You can use the SetRules(IAccessRule[]) method to set access rules. This method raises an exception if the rules are set earlier (if the reporting control has already set its rules).

The following code snippets (auto-collected from DevExpress Examples) contain references to the TrySetRules(IAccessRule[]) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also