ASP.NET Sharepoint CSOM error: An existing connection was forcibly closed by the remote host
ASP.NET Sharepoint CSOM error: An existing connection was forcibly closed by the remote host
我在 .NET Framework 4.7.2 下有一个 ASP.NET 应用程序 运行。
在我的应用程序中,我试图连接到我的 Sharepoint 站点以创建或重命名文件夹。
不幸的是,我遇到了以下错误。
我一直在互联网上四处搜索,发现很多文章都在谈论 TLS,但由于 .NET Framework 4.7.2,我的应用程序默认使用 TLS 1.2。
有谁知道错误的reason/background吗?
(我的本地机器上没有错误(没有 SSL),只有在使用 SSL 部署到我的托管环境后才会出现错误)
这是完整的错误信息:
Server Error in '/' Application.
An existing connection was forcibly closed by the remote host
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.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
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.
Stack Trace:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +106
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +291
System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +32
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +156
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +281
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +49
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +162
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +542
System.Net.TlsStream.CallProcessAuthentication(Object state) +42
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +228
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +21
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +64
System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +778
System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +52
System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +103
System.Net.ConnectStream.WriteHeaders(Boolean async) +388
[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
System.Net.HttpWebRequest.GetResponse() +1399
Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() +37
Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() +514
Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() +126
Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +44
Axius.Presentation.Website.frmAdminProjectDossierDetail.chkDossierSharepoint_CheckedChanged(Object sender, EventArgs e) in C:\inetpub\wwwroot\Axius.Presentation.Website\frmAdminProjectDossierDetail.aspx.cs:3637
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e) +116
System.Web.UI.WebControls.CheckBox.RaisePostDataChangedEvent() +139
System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +12
System.Web.UI.Page.RaiseChangedEvents() +132
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1559
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0
这是代码:
using (ClientContext context = new ClientContext("https://mysite.sharepoint.com/"))
{
var passWord = new SecureString();
foreach (char c in "XXXXXXXXXX".ToCharArray()) passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("my@account.com", passWord);
List oList = context.Web.Lists.GetByTitle(@"Gedeelde documenten");
FolderCollection folders = oList.RootFolder.Folders;
context.Load(folders);
context.ExecuteQuery(); //this is frmAdminProjectDossierDetail.aspx.cs:3637 visible in the error
foreach (Folder folderr in folders)
{
if (folderr.Name == "01 PROJECTEN DOCS")
{
//code continues
}
}
}
TLS 连接至少有两个部分:版本和密码套件。您需要检查本地计算机上的密码:
https://docs.microsoft.com/en-us/powershell/module/tls/get-tlsciphersuite?view=windowsserver2022-ps
那么您应该检查共享点站点上可用的密码:
https://www.ssllabs.com/ssltest/
至少有一个密码必须匹配才能完成连接。
我在 .NET Framework 4.7.2 下有一个 ASP.NET 应用程序 运行。 在我的应用程序中,我试图连接到我的 Sharepoint 站点以创建或重命名文件夹。 不幸的是,我遇到了以下错误。 我一直在互联网上四处搜索,发现很多文章都在谈论 TLS,但由于 .NET Framework 4.7.2,我的应用程序默认使用 TLS 1.2。
有谁知道错误的reason/background吗? (我的本地机器上没有错误(没有 SSL),只有在使用 SSL 部署到我的托管环境后才会出现错误)
这是完整的错误信息:
Server Error in '/' Application.
An existing connection was forcibly closed by the remote host
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.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
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.
Stack Trace:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +106
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +291
System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +32
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +156
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +281
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +49
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +162
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +542
System.Net.TlsStream.CallProcessAuthentication(Object state) +42
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +228
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +21
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +64
System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +778
System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +52
System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +103
System.Net.ConnectStream.WriteHeaders(Boolean async) +388
[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
System.Net.HttpWebRequest.GetResponse() +1399
Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() +37
Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() +514
Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() +126
Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +44
Axius.Presentation.Website.frmAdminProjectDossierDetail.chkDossierSharepoint_CheckedChanged(Object sender, EventArgs e) in C:\inetpub\wwwroot\Axius.Presentation.Website\frmAdminProjectDossierDetail.aspx.cs:3637
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e) +116
System.Web.UI.WebControls.CheckBox.RaisePostDataChangedEvent() +139
System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +12
System.Web.UI.Page.RaiseChangedEvents() +132
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1559
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0
这是代码:
using (ClientContext context = new ClientContext("https://mysite.sharepoint.com/"))
{
var passWord = new SecureString();
foreach (char c in "XXXXXXXXXX".ToCharArray()) passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("my@account.com", passWord);
List oList = context.Web.Lists.GetByTitle(@"Gedeelde documenten");
FolderCollection folders = oList.RootFolder.Folders;
context.Load(folders);
context.ExecuteQuery(); //this is frmAdminProjectDossierDetail.aspx.cs:3637 visible in the error
foreach (Folder folderr in folders)
{
if (folderr.Name == "01 PROJECTEN DOCS")
{
//code continues
}
}
}
TLS 连接至少有两个部分:版本和密码套件。您需要检查本地计算机上的密码:
https://docs.microsoft.com/en-us/powershell/module/tls/get-tlsciphersuite?view=windowsserver2022-ps
那么您应该检查共享点站点上可用的密码: https://www.ssllabs.com/ssltest/
至少有一个密码必须匹配才能完成连接。