2013-02-19 39 views
1

我遷移代碼調用從2010年至2013年的Project Server 2013 PSI從SharePoint 2013

我有我在Sharepoint調用PSI部署一個用戶控件。在2010年它運作良好。現在在2013和聲明身份驗證中,我總是會得到:「HTTP請求未經客戶端身份驗證方案'Ntlm'的授權。從服務器收到的身份驗證頭是'NTLM,Negotiate'。」當我用任何用戶(甚至是項目管理員)調用任何PSI(甚至GetCurrentUserUid)時。

它看起來像憑證不傳遞給PSI,它將其稱爲匿名。任何人都可以幫忙

我從SharePoint執行的代碼又如:

ProjectContext projContext = new ProjectContext(PROJECT_SERVER_URL); 
projContext.Load(projContext.EnterpriseResources); 
projContext.ExecuteQuery(); 

我得到拒絕訪問。

謝謝

+0

你修改你的app.config尚未憑證?看看[我的答案在這裏]的後半部分(http://stackoverflow.com/questions/2608887/sharepoint-web-services-the-http-request-is-unauthorized-with-client-authenti/2609909#2609909)查看您需要修改的部分。 – 2013-02-20 13:20:39

+0

@Kit在我的情況下,它將是web.config。我通過代碼配置客戶端,因此web.config中沒有任何內容。 'This.HttpBinding = 新的BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); this.HttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;' – David 2013-03-04 10:08:32

回答

-1

您需要首先登錄到SharePoint。下面的位將給你一個有效的上下文。

public static ProjectContext GetContext() 
{ 
    ProjectContext projContext; 
    using (projContext = new ProjectContext("pwaUrl"])) 
    { 
     SecureString passWord = new SecureString(); 

     foreach (char c in "yourPassword".ToCharArray()) passWord.AppendChar(c); 

     projContext.Credentials = new SharePointOnlineCredentials("youremailaddress", passWord); 
    } 
    return projContext; 
} 
+0

您的解決方案不符合我的需要。我想使用當前的用戶憑據,而不是硬編碼的... – David 2016-06-03 07:58:58

0
public static ProjectContext GetContext() 
    { 
     ProjectContext projContext; 
     using (projContext = new ProjectContext("pwaUrl")) 
     { 
      SecureString passWord = new SecureString(); 

      foreach (char c in "YourEmailPassword".ToCharArray()) passWord.AppendChar(c); 

      projContext.Credentials = new SharePointOnlineCredentials("YourEmail", passWord); 
     } 
     return projContext; 
    } 
0

您是否嘗試過使用設置 projContext.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

+0

應該是一個評論 – 2016-08-12 09:30:03

+0

很久以前,但我認爲我試過 – David 2016-08-16 12:12:11

+0

我無法添加評論 – Ariwibawa 2016-12-02 07:13:30