Access the Security System in Code 在代码中访问安全系统
This lesson will guide you through using the static SecuritySystem 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.
本课将指导您使用静态安全系统类检查用户是否具有特定权限。具有修改演示任务对象权限的用户可以访问 SetTask 操作。
Note 注意
Before proceeding, we recommend that you review the following lessons.
在继续之前,我们建议您复习以下课程。
Using the Security System
使用安全系统
Add an Action with Option Selection
添加具有选项选择的操作
-
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.
-
打开您在"使用选项选择添加操作"一课中创建的TaskActionsController.cs(TaskActions控制器.vb)文件。添加"using"指令并修改激活的事件处理程序,如下所示。
using DevExpress.ExpressApp.Security; //... public partial class TaskActionsController : ViewController { // ... private void TaskActionsController_Activated(object sender, EventArgs e) { View.SelectionChanged += new EventHandler(View_SelectionChanged); UpdateSetTaskActionState(); } void View_SelectionChanged(object sender, EventArgs e) { UpdateSetTaskActionState(); } private void UpdateSetTaskActionState() { bool isGranted = true; foreach(object selectedObject in View.SelectedObjects) { bool isPriorityGranted = SecuritySystem.IsGranted(new PermissionRequest(ObjectSpace, typeof(DemoTask), SecurityOperations.Write, selectedObject, "Priority")); bool isStatusGranted = SecuritySystem.IsGranted(new PermissionRequest(ObjectSpace, typeof(DemoTask), SecurityOperations.Write, selectedObject, "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.
使用添加的代码,将为具有所选 DemoTask 对象的"优先级"和"状态"属性的写入权限的用户激活"设置任务操作"。
- 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 Comprehensive Tutorial. To learn more about the main concepts for building business applications and extending XAF tools, refer to the Concepts section. If you need task-based help, take a look at the Task-Based Help section. To learn how to deploy XAF applications, review the Deployment Tutorial.
这是综合教程的最后一课。要了解有关构建业务应用程序和扩展 XAF 工具的主要概念的详细信息,请参阅概念部分。如果您需要基于任务的帮助,请查看基于任务的帮助部分。要了解如何部署 XAF 应用程序,请查看部署教程。
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端