Security Permissions Caching
Security permission caching is implemented in Security Adapters - classes used by the Security System to process and cache security permission requests. Each Security Adapter has the corresponding Security Adapter Provider class, which is used internally to register the adapter. XPO adapters and their providers are located in the DevExpress.ExpressApp.Security.Xpo.v17.1.dll assembly. The provider and adapter for the Entity Framework are available in the DevExpress.ExpressApp.Security.EF.v17.1.dll assembly. Both these assemblies (XPO and EF) contain the SecurityAdapterHelper class that exposes static methods that enable/disable Security Adapters. So, in your code, you do not need to access Security Adapters directly. This topic describes how to enable and customize caching using the SecurityAdapterHelper class.
Enable Caching in Code
When creating a new XAF project, caching is enabled by the Solution Wizard. The wizard adds the following code line to the WinApplication.cs (WinApplication.vb) and WebApplication.cs (WebApplication.vb) files.
新建項目時,可以在創向導中選擇這個選薦.也可以在代碼中修改.(winapplication.cs/webapplication.cs)中:
using DevExpress.ExpressApp.Security; // ... SecurityAdapterHelper.Enable();
in the constructor of your platform-agnostic module located in the Module.cs (Module.vb) file;To enable or customize Security permissions caching in an existing application, use the same code, or use another overload of the Enable method that takes an ReloadPermissionStrategy enumeration value. You can call this static method from any place of your code, which is executed before a user is logged on, e.g.:
- in the Main method of the WinForms application located in the Program.cs (Program.vb) file, before the WinApplication.Start call;
- in the Application_Start method of the ASP.NET application located in the Global.asax.cs (Global.asax.vb) file, before the WebApplication.Start call.
The Solution Wizard uses the second and third locations.
Reload Permission Strategies
Security Adapters support various modes of reloading the security permissions. The available modes are listed in the ReloadPermissionStrategy enumeration. There is an overload of the SecurityAdapterHelper.Enable method that takes the reloadPermissionStrategy parameter - use it to change the mode. By default, the NoCache mode is used. Each Session (in XPO) or DBContext (in Entity Framework) operates with the most recent permissions loaded from the database in this mode. You can use the CacheOnFirstAccess mode instead. Permissions are loaded and cached when the corresponding secured data is accessed for the first time, cached permissions are used until the user is logged off in this mode. This mode allows you to significantly reduce the number of database requests when working with secured data.
安全適配器支持各種重新加載安全權限的模式。可用模式在 ReloadPermissionStrategy 枚舉中列出。SecurityAdapterHelper 的重載. 啟用采用 reloadPermissionStrategy 參數的方法-使用它來更改模式。默認情況下, 使用緩存模式。每個會話 (在 xpo 中) 或 DBContext (在實體框架中) 都使用此模式中從數據庫加載的最新權限。您可以改用 CacheOnFirstAccess 模式。當第一次訪問相應的安全數據時, 將加載和緩存權限, 直到用戶在此模式下注銷時才使用緩存的權限。此模式允許您在使用安全數據時顯著減少數據庫請求的數量。
文章列表