0

我越來越試圖通過SharePoint API從ASP.NET MVC應用程序中訪問SharePoint 2010網站時,出現以下錯誤:訪問被拒絕從MVC應用程序中訪問的SharePoint API

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 

MVC應用與SharePoint安裝上的站點管理員的應用程序池用戶以64位模式駐留在IIS7上。 重要的是,調用SharePoint API的WCF服務在同一個Web應用程序中託管,沒有任何問題,所以我覺得很奇怪我無法從Controller Action獲取相同的結果。

我曾嘗試:

  • 設置System.web/identity impersonate="true" etc etc
  • 設置System.web/authentication mode="Windows"
  • 以上的組合。

不管是什麼上面試過,System.Security.Principal.WindowsIdentity.GetCurrent().Name返回預期的應用程序池用戶,但Request.IsAuthenticated返回false。這既是編程通過調試檢查,以及在事件日誌中驗證:

Event code: 4011 
Event message: An unhandled access exception has occurred. 
... 
Process information: 
    Process ID: 1234 
    Process name: w3wp.exe 
    Account name: VALIDDOMAIN\VALIDUSER 

Request information: 
    Request URL: http://localhost:2000/Service/ 
    Request path: /Service/ 
    User host address: ::1 
    User: 
    Is authenticated: False 
    Authentication Type: 
    Thread account name: VALIDDOMAIN\VALIDUSER 

我怎麼能說一個標準MVC3 Web應用程序控制器操作在SharePoint 2010 API?

更新01:

下面是我使用的代碼:

using (SPSite site = new SPSite(siteUrl)) 
    { 
     workflow.SPSiteCollectionID = site.ID; 

     using (SPWeb web = site.OpenWeb()) 
     { 
      foreach (SPGroup group in web.SiteGroups) 
      { 
       //some code 
      } 
     } 
    } 

這無法上線foreach (SPGroup group in web.SiteGroups)

+0

您定位哪個框架? 3.5? – int32

+0

.NET 3.5 - 這是我們可以與SharePoint 2010 API一起使用的唯一版本。 –

+0

是的,我知道,這就是爲什麼我問:P,所以當你構建一個新的SPSite對象的權利時,拒絕訪問?您是否嘗試過提升特權?另外,在wcf服務中,您是否在任何地方(config/code)設置了默認(網絡)憑據? – int32

回答

2

試試這個: 新的SPSite(SITEURL,SystemAccount.UserToken )