Articles about European Sharepoint Hosting Service
SharePoint Hosting – The Underlying Connection Was Closed: An Unexpected Error Occurred
SharePoint Provider Hosted
The underlying connection was closed: An unexpected error occurred on a send. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote host.
Recently, I was getting this error while deploying the SharePoint Provider hosted app in the Azure app service.
Exact Error
The underlying connection was closed: An unexpected error occurred on a send. Innerer Exception 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)
Then, I started debugging locally with username and password and still getting errors while generating token as shown,
Token request failed. Innerer Exception System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2WebRequest.GetResponse()
at Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2S2SClient.Issue(String securityTokenServiceUrl, OAuth2AccessTokenRequest oauth2Request)
The above error message gave me some hints and the issue is related to security protocol.
Solution: After a bit of research, I found that this error was happening only in older applications. This can be fixed by updating the security protocol.
We need to add the following code before doing authentication or generating tokens.
We can add this line of code just before the authentication part as shown.
Alternatively, for manual authentication (sample).
However, if you are creating the provider-hosted app with the latest version, then this issue has already been fixed.
Print article | This entry was posted by Peter on August 19, 2021 at 3:50 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |