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

转载于:https://www.cnblogs.com/luyj00436/p/11489360.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值