2014-03-01 127 views
0

在我的網站中,我使用添加服務參考,我讀了一些SharePoint列表, 我第一次打開我的電腦,在VS發生錯誤! 之後,它的作品,當我想試試我的IIS或服務器ISS,會出現同樣的錯誤,並沒有解決:我的VisualStudio網站運行良好,但在IIS上沒有?

Server Error in '/' Application. 
Unauthorized 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.Services.Client.DataServiceClientException: Unauthorized 

源錯誤:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

堆棧跟蹤:

[DataServiceClientException: Unauthorized] 
    System.Data.Services.Client.QueryResult.Execute() +656 
    System.Data.Services.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +349 

[DataServiceQueryException: An error occurred while processing this request.] 
    System.Data.Services.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +562697 
    System.Data.Services.Client.DataServiceQuery`1.Execute() +113 
    System.Data.Services.Client.DataServiceQuery`1.GetEnumerator() +22 
    _default.Page_Load(Object sender, EventArgs e) in c:\Users\user\Desktop\TPPG\tppg.com\default.aspx.cs:58 
    System.Web.UI.Control.LoadRecursive() +71 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178 

而這個錯誤發生在我想從SharePoint列表讀取數據的foreach循環中!

我能做什麼!?

這是我的代碼,之後添加服務引用在頁面加載:

ServiceReference1.TPPDataContext obj = new ServiceReference1.TPPDataContext(new Uri("http://sharepoint/_layouts/viewlsts.aspx/_vti_bin/ListData.svc")); 
    obj.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; 
    var sourc = obj.Announcement; 

    foreach (var item in sourc) 
    { 
     if (item.WF1 == "Management1" && item.AnnounceTypeValue == "Management") 
     { 
      Place[0] = item.Text1; 
     } 
     else if (item.WF1 == "Sharepoint1" && item.AnnounceTypeValue == "Sharepoint") 
     { 
      Place[1] = item.Text1; 
     } 
     else if (item.WF1 == "Admin1" && item.AnnounceTypeValue == "Admin") 
     { 
      Place[2] = item.Text1; 
     } 
     else if (item.WF1 == "Training1" && item.AnnounceTypeValue == "Training") 
     { 
      Place[3] = item.Text1; 
     } 
     else if (item.WF1 == "Others1" && item.AnnounceTypeValue == "Others") 
     { 
      Place[4] = item.Text1; 
     } 
    } 
+0

顯示您的代碼。 –

+0

好吧,很明顯,您的Web應用程序運行的上下文中的用戶帳戶沒有SharePoint權限。 –

回答

0

也許這是行不通的,因爲在IIS應用程序的IIS用戶下運行,或者它設置爲匿名用戶。您可以嘗試2件事:

  1. 嘗試將IIS中的應用程序設置爲集成身份驗證,如果您的用戶有權限的話。

  2. (OR)代替的DefaultCredentials的,具有權限設置用戶到SharePoint:

    obj.Credentials =新System.Net.NetworkCredential( 「用戶」, 「密碼」, 「結構域」);

相關問題