zoukankan      html  css  js  c++  java
  • DevExpress XAF 获取当前用户

    代码

    1 Owner = Session.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId);

    用户属性

      应用程序的功能可能取决于当前用户。因此,需要获取用户名、用户ID或者整个用户对象。以下是SecuritySystem类公开的属性。

    • SecuritySystem.CurrentUserName      --当前用户名
    • SecuritySystem.CurrentUserId            --当前用户ID
    • SecuritySystem.UserType                   --当前用户类型
    • SecuritySystem.CurrentUser               --当前用户

    SecuritySystem.CurrentUser属性

     1 using DevExpress.ExpressApp;
     2 using DevExpress.ExpressApp.Actions;
     3 using DevExpress.Persistent.Base;
     4 // ... 
     5 public class ShowCurrentUserController : WindowController {
     6     public ShowCurrentUserController() {
     7         PopupWindowShowAction showCurrentUserAction = new PopupWindowShowAction(
     8         this, "ShowCurrentUser", PredefinedCategory.Edit);
     9         showCurrentUserAction.CustomizePopupWindowParams += ShowCurrentUserAction_CustomizePopupWindowParams;
    10     }
    11 
    12     private void ShowCurrentUserAction_CustomizePopupWindowParams(
    13         object sender, CustomizePopupWindowParamsEventArgs e) {
    14         IObjectSpace newObjectSpace = Application.CreateObjectSpace(SecuritySystem.CurrentUser.GetType());
    15         object currentUser = newObjectSpace.GetObject(SecuritySystem.CurrentUser);
    16         e.View = Application.CreateDetailView(newObjectSpace, currentUser);
    17     }
    18 }

     访问标准当前用户

      当需要在筛选条件中使用当前用户时,请使用CurrentUserId函数criteria操作符。

    初始化对象所有者

      将当前对象引用分配给Owner对象。

    1 void IXafEntityObject.OnCreated() {
    2     Owner = objectSpace.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId);
    3 }

       XPO对象

    1 public override void AfterConstruction() {
    2     base.AfterConstruction();
    3     if (SecuritySystem.CurrentUser != null) {
    4         Owner = Session.GetObjectByKey<PermissionPolicyUser>(SecuritySystem.CurrentUserId);
    5     }
    6 }

     根据对象那个所有者配置权限  

      为要筛选的对象类型添加类型权限,并将其AllowRead属性设置为false。

      向该类型权限添加对象权限,将其AllowRead属性设置为true,将Criteria属性设置为“Owner”。Oid = CurrentUserId ()”。

    参考网址

      [1] https://documentation.devexpress.com/eXpressAppFramework/113152/Task-Based-Help/Security/How-to-Get-the-Current-User-in-Code

  • 相关阅读:
    怎样判断某个分辨率是不是 16:9
    最简单的判断是否为IE浏览器的方法
    S4 smartforms切换到非word编辑器
    字符串中数字和汉字之前打空格
    elasticsearch 中term查询
    小程序 反编译 pc微信
    vue-element-admin vue-amap使用高德地图 文档没有示例代码
    高德地图 自适应 显示多个点标记
    laravel5 清理 bootstrap/cache/config.php
    element-admin 上传 跨域 问题 http-request
  • 原文地址:https://www.cnblogs.com/luyj00436/p/11489360.html
Copyright © 2011-2022 走看看