SharePoint 服务器身份验证错误

发布于 2024-11-28 10:59:04 字数 2619 浏览 0 评论 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 网站上突然发生此错误?

So I was working with a hosted SharePoint site before and everything was working fine when I authenticated to that site using the code below:

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());
    }
}

Now, I had a sandbox created for me and I can access (manually) the site just fine. However, when I try to authenticate to the site through my c# code, I get an error.

And other than the username, password, and domain, all I have really changed is private static ClientContext clientContext = new ClientContext("http://sandbox");.

The error I get in the console is:

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

Does anyone know why suddenly this error is occurring on the new SharePoint site?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云醉月微眠 2024-12-05 10:59:04

在每个executeQuery() 之前都需要一个凭据

,并且需要两个executeQuery() 来分别加载站点和列表。

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

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

You need a credential before every executeQuery()

and you need two executeQuery() for loading the site and list separately.

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

clientContext.Credentials = credentials;
       clientContext.Load(list);
       clientContext.ExecuteQuery();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文