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

猜你喜欢

转载自www.cnblogs.com/luyj00436/p/11489360.html