0

そのため、以前はホストされた 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 サイトで突然このエラーが発生する理由を知っている人はいますか?

4

1 に答える 1