0

所以我與前託管SharePoint站點工作,一切工作正常,當我用下面的代碼驗證該網站:SharePoint服務器驗證錯誤

private static NetworkCredential credentials = new NetworkCredential(username, password, domain); 
private static ClientContext clientContext = new ClientContext("https://thisonesite.com/hosting/151"); 
private static Web site = clientContext.Web; 
private static List list = site.Lists.GetByTitle(listName); 

private static void sharepointLogin() 
{ 
    try 
    { 
     //Loads credentials needed for authentication 
     clientContext.Credentials = credentials; 
     //Loads the site 
     clientContext.Load(site); 
     //Loads the site list 
     clientContext.Load(list); 
     //Executes the previous queries on the server 
     clientContext.ExecuteQuery(); 
     //Writes out the title of the SharePoint site to the console 
     Console.WriteLine("Title: {0}", site.Title); 
    } 
    catch (Exception e) 
    { 
     Console.WriteLine(e.ToString()); 
    } 
} 

現在,我不得不爲我創造了一個沙箱我可以很好地訪問(手動)網站。但是,當我嘗試通過我的c#代碼對該網站進行身份驗證時,出現錯誤。

除了用戶名,密碼和域名之外,我真正改變的只有private static ClientContext clientContext = new ClientContext("http://sandbox");

我在控制檯得到的錯誤是:

System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host 
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
--- End of inner exception stack trace --- 
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) 
--- End of inner exception stack trace --- 
at System.Net.HttpWebRequest.GetResponse() 
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() 
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) 
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() 
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() 
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() 
at ConsoleApp1.SharePointAccess.sharepointLogin() in C:\directortypath 

有誰知道爲什麼突然這個錯誤是新的SharePoint網站上發生的?

+0

請不要在標題中放置「C# - 」等標籤。你已經有了[tag:C#]標籤,那就更好了。 –

+0

@John對不起,我會注意到,供將來參考。 –

+0

我假設你已經通過這段代碼來看看哪一行實際上是拋出異常。這是什麼?我也沒有看到「list」變量的定義... – meccaneko

回答

0

你每天的executeQuery()

之前需要一個證書,你需要兩個的executeQuery()爲單獨加載網站和列表。

clientContext.Credentials = credentials; 
     clientContext.Load(site); 
     clientContext.ExecuteQuery(); 

clientContext.Credentials = credentials; 
     clientContext.Load(list); 
     clientContext.ExecuteQuery(); 
相關問題