2013-12-14 54 views
0

我使用電燈開關在VB中,我需要檢查是給定的用戶具有特定的權限(「用戶」)或不 我嘗試下面的代碼:檢查特定用戶在LightSwitch中特定的權限

 Dim myper = Me.DataWorkspace.SecurityData.Permissions.Where(Function(p) p.Id.Equals("LightSwitchApplication:User", StringComparison.OrdinalIgnoreCase)).SingleOrDefault 


     If Not myper Is Nothing Then 
      Dim myu = myper.RolePermissions.SelectMany(Function(u) u.Role.RoleAssignments).Select(Function(us) us.UserName = UserName) 
      If Not myu Is Nothing Then 
       ' this mean no user has the user permission! 
       results.AddPropertyError("found") 
      Else 
       'user has been found for this permission 
       results.AddPropertyError("not found") 
      End If 
     Else 
      'this mean no roles has this permission ! 

     End If 

但不幸的是,myu對象總是沒有返回我不知道爲什麼,對不起,但我是新的LINQ。

回答

0

您應該爲此使用Application.User對象。

在CSHARP:

if(this.Application.User.HasPermission(Permissions.PermXYZ)) 
{ 
    //permitted 
} 
+0

您的代碼正在檢查登錄的用戶,但在這裏我需要檢查給定的用戶名字符串。 –

-1

如果你想檢查用戶名:

如果(this.Application.User.Name.Equals( 「用戶名」)){ enter code here }

相關問題