[英]ServerUnauthorizedAccessException when trying to connect to Project Server through CSOM
我在Microsoft SharePoint 2013 onPremise服務器場上安裝了Microsoft Project Server 2013。
我正在嘗試構建一個WebPart,該WebPart應該從TeamSite通過CSOM通過CSOM連接到Project Server,以獲得項目信息。
這是我的超級簡單代碼:
string pwaPath = "http://sp2013/PWA";
ProjectContext projContext;
projContext = new ProjectContext(pwaPath);
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
當嘗試執行它時,出現以下錯誤:
ServerUnauthorizedAccessException
當我添加
projContext.Credentials = new NetworkCredential("administrator", "pass", "domain");
有用! 但是我如何使用已登錄的用戶來編寫代碼,導致上面傳遞的憑據是當前登錄的用戶憑據。
您的代碼將不起作用,因為場解決方案無法在SharePoint用戶的上下文中執行。 如果選中System.Security.Principal.WindowsIdentity.GetCurrent()
,則會看到當前身份是IIS內置的IUSR
。 這是ClientContext
將用於發出請求的身份。
如果使用SPSecurity.RunWithElevatedPrivileges()
提升權限, SPSecurity.RunWithElevatedPrivileges()
使用應用程序池標識執行代碼。 在某些情況下,這可能就足夠了,但由於所有用戶都將能夠訪問資源,因此可能也不安全。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.