2011-05-05 96 views
3

以下代碼在InitializeClientContextFromName失敗,並且「值不在預期範圍內」。它適用於其他開發人員的機器。AZMan:InitializeClientContextFromName失敗,「值不在預期範圍內」。

我應該跟進的任何線索?我不是很熟悉,在AzMan的所有...

private List<string> SyncAzManRoles(ActiveDirectoryMembershipProvider provider) 
    { 
     List<string> userAzManRoles = new List<string>(); 

     AzAuthorizationStoreClass store = new AzAuthorizationStoreClass(); 
     if (store == null) 
     { 
      AuthTrace("Azman store is not available"); 
      throw new InvalidOperationException("The azman store is not available"); 
     } 
     store.Initialize(0, ConfigurationManager.ConnectionStrings 
        ["LocalPolicyStore"].ConnectionString, null); 

     IAzApplication3 app = store.OpenApplication(Security.ApplicationName, null) as IAzApplication3; 
     if (app == null) 
     { 
      AuthTrace("Azman application is not available"); 
      throw new InvalidOperationException("The azman application is not available"); 
     } 

     IAzClientContext3 clientContext = null; 
     try 
     { 
      clientContext = app.InitializeClientContextFromName(_username, 
       provider.Name, null) as IAzClientContext3; 
+0

得到了同樣的問題,很想找到答案! – 2011-05-06 05:15:24

回答

2

我使用InitializeClientContextFromToken方法,而不是InitializeClientContextFromName解決了這個。

在我的情況下,它被一個ASP.NET Web應用程序

ulong token = 0; 

var principal = User as WindowsPrincipal; 
if (principal != null) 
{ 
    var identity = (WindowsIdentity) principal.Identity; 

    ViewBag.Identity = identity.Name; 
    token = (ulong) identity.Token.ToInt64(); 
} 

// Server 2008 or Vista required to use IAzClientContext3 
// Using token 0 uses app pool identity 
var _clientContext = (IAzClientContext3) _azManApp.InitializeClientContextFromToken(token); 

內部使用如果在傳遞零作爲標記值,​​爲Web應用程序導致使用App池標識。否則,如果用戶使用WindowsIdentity登錄,則Token屬性的值也起作用。

對於桌面應用程序,您可能只需使用零令牌即可使用當前用戶的身份。

相關問題