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
有志者,事竟成,破釜沉舟,百二秦關終屬楚; 苦心人,天不負,臥薪嘗膽,三千越甲可吞吳。

浙公網安備 33010602011771號