System.Net.Sockets.SocketException:'An existing connection was forcibly closed by the remote host' 使用 SharePoint Online 低信任身份验证
System.Net.Sockets.SocketException: 'An existing connection was forcibly closed by the remote host' with SharePoint Online low trust authentication
我们正在使用 Oauth 在 Azure 中使用 SharePoint 在线验证我们的云服务 - https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/three-authorization-systems-for-sharepoint-add-ins#low-trust 我们收到此错误 - System.Net.Sockets.SocketException:'An existing connection was forcibly closed by the remote host'
尝试下面的 clientContext.ExecuteQuery() 代码时。
Microsoft.SharePoint.Client.User spUser = null;
try
{
using (clientContext)
{
if (clientContext != null)
{
spUser = clientContext.Web.CurrentUser;
clientContext.Load(spUser);
clientContext.ExecuteQuery();
return spUser.LoginName.Split('|')[2];
}
}
return string.Empty;//no context = no id
}
知道这个问题可能是什么或如何解决这个问题吗?谢谢
所以添加这个解决了问题:
using System.Net;
using System.Security.Authentication;
在 clientContext.ExecuteQuery();
之前添加以下代码
const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
潜在的问题似乎是我们正在使用 .net framework 4.5,我们必须将其升级到最新版本才能消除此错误。
这里有更多解释- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host
我们正在使用 Oauth 在 Azure 中使用 SharePoint 在线验证我们的云服务 - https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/three-authorization-systems-for-sharepoint-add-ins#low-trust 我们收到此错误 - System.Net.Sockets.SocketException:'An existing connection was forcibly closed by the remote host'
尝试下面的 clientContext.ExecuteQuery() 代码时。
Microsoft.SharePoint.Client.User spUser = null;
try
{
using (clientContext)
{
if (clientContext != null)
{
spUser = clientContext.Web.CurrentUser;
clientContext.Load(spUser);
clientContext.ExecuteQuery();
return spUser.LoginName.Split('|')[2];
}
}
return string.Empty;//no context = no id
}
知道这个问题可能是什么或如何解决这个问题吗?谢谢
所以添加这个解决了问题:
using System.Net;
using System.Security.Authentication;
在 clientContext.ExecuteQuery();
之前添加以下代码const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
潜在的问题似乎是我们正在使用 .net framework 4.5,我们必须将其升级到最新版本才能消除此错误。
这里有更多解释- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host