locked
Unable to connect to Azure Blob storage from IIS RRS feed

  • Question

  • Hi,

    We have a web application which stores and retrieves files from Azure blob storage hosted in Windows Server 20012 R2 Standard x64(Build 9600). It was working earlier and all of the sudden it stopped working in the same server. 

    Interestingly, while accessing the same Azure storage from console application, it is working as expected in the same server. 

    .Net Framework version: 4.6.1

    IIS Version: 8.5.9600.16384

    Below is the error we are getting while accessing the file storage from Web application. 

    Error Type - Microsoft.WindowsAzure.Storage.StorageException
    Error Source - Microsoft.WindowsAzure.Storage
    Error Details - 
    Microsoft.WindowsAzure.Storage.StorageException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> 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.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.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
       at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.ConnectStream.WriteHeaders(Boolean async)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.GetResponse()
       at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 744
       --- End of inner exception stack trace ---
       at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 649
       at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.OpenRead(AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlob.cs:line 51

    The following is the code for accessing the storage location.

    string localFile="c:\myfolder\textfile";
    string azureConnectionString="";
    string myContainerName="";
    string filePath=@"path\to\azure\file";
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azureConnectionString);
    CloudBlobClient client = storageAccount.CreateCloudBlobClient();
    var container = client.GetContainerReference(myContainerName);
    
    var reference = container.GetBlockBlobReference(filePath);
    var s = reference.OpenRead();
    using (var ms = new FileStream(filePath, FileMode.CreateNew))
    {
    	s.CopyTo(ms);
    	ms.Close();
    	s.Close();
    }

    Any help would be appreciated.

    Thank you.


    • Edited by Saba1990 Thursday, September 19, 2019 10:01 AM
    Thursday, September 19, 2019 9:58 AM

Answers

  • Thank you Sumanth for your suggestions.

    We figured out later that somehow TLS 1.2 is enabled in the server by adding entries to registry.

    The change was made to the registry keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols.

    After reverting the changes, application hosted in IIS can able to communicate with Azure storage as usual.


    Thank you.!

    Friday, September 20, 2019 12:07 PM

All replies

  • Apologies for the delay! There are several reason leadings to such error so you may check the following.

    If possible, can you restart the server.

    Your ISP is not blocking your connection due to any reason

    Firewall in your system allows the connection (protocol, host & port)

    I have to say it must be a network issue. Please check the network configuration of your server.

    Hope this helps! 

    Kindly let us know if the above helps or you need further assistance on this issue.
    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    Friday, September 20, 2019 11:52 AM
  • Thank you Sumanth for your suggestions.

    We figured out later that somehow TLS 1.2 is enabled in the server by adding entries to registry.

    The change was made to the registry keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols.

    After reverting the changes, application hosted in IIS can able to communicate with Azure storage as usual.


    Thank you.!

    Friday, September 20, 2019 12:07 PM