Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 连接到Azure云Blob存储失败,证书无效_C#_.net_Security_Azure - Fatal编程技术网

C# 连接到Azure云Blob存储失败,证书无效

C# 连接到Azure云Blob存储失败,证书无效,c#,.net,security,azure,C#,.net,Security,Azure,我正在使用Azure存储客户端库连接到我的Azure blob存储并发布一些文件。以下代码是我用来建立连接和创建blob容器的代码的摘录: var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("settingsName")); client = storageAccount.CreateCloudBlobClient(); var container = client.GetC

我正在使用Azure存储客户端库连接到我的Azure blob存储并发布一些文件。以下代码是我用来建立连接和创建blob容器的代码的摘录:

var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("settingsName"));

client = storageAccount.CreateCloudBlobClient();

var container = client.GetContainerReference("containerName");
            container.CreateIfNotExists();
这在我的本地机器上运行良好。但是,如果我尝试在不同的服务器上运行完全相同的代码,则会出现以下异常:

Microsoft.WindowsAzure.Storage.StorageException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, 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)
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
   at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists(BlobContainerPublicAccessType accessType, BlobRequestOptions requestOptions, OperationContext operationContext)

有人知道是什么导致了这一切吗?我已经用谷歌搜索这个问题好几天了,没有任何解决办法。

这个线程已经休眠了一段时间,但我最近遇到了同样的问题;我想我会分享我的成果,希望将来其他人能从中受益

尝试从服务器写入Azure存储blob时,我们收到了相同的错误,尽管相同的代码在本地和其他服务器上运行良好:

Microsoft.WindowsAzure.Storage.StorageException:基础连接已关闭:无法为SSL/TLS安全通道建立信任关系。-->System.Net.WebException:基础连接已关闭:无法为SSL/TLS安全通道建立信任关系

首先,我们验证了机器上安装了正确的证书颁发机构。通常,这可能是罪魁祸首。然而,在我们的案例中,我们拥有所有必要的证书颁发机构

最后出现的问题是,服务器没有解析存储帐户的正确IP地址(yourstorageaccountname.blob.core.windows.net)

在本地,尝试从命令提示符ping存储帐户,如下所示:

ping yourstorageaccountname.blob.core.windows.net

您应该看到,来自本地计算机的ping能够解析blob帐户的IP地址(13.88.144.248等)

现在,请尝试从您的服务器ping blob帐户,您将在那里获得此异常。如果ping无法解析IP地址,或者正在解析错误的IP地址(如我的情况),您可能已经发现了问题

如果是这种情况,添加一个简单的映射到C:\Windows\System32\drivers\etc\hosts文件可以解决我们的问题。如果您有相同的问题,向文件添加IP映射应该可以解决它。映射应该将本地ping的IP映射到blob帐户的主机名。下面是一个例子:

13.88.144.248 yourstorageaccountname.blob.core.windows.net


请注意,您必须以管理员身份运行文本编辑器(记事本等)才能正确保存主机文件。

您可以共享存储帐户的连接设置吗?请删除或屏蔽敏感信息,如帐户密钥。我的应用设置如下:它在我的本地计算机上工作,在服务器上完全相同。您还可以尝试将azure证书添加为受信任的证书。我知道验证过程中出现了问题,并且证书似乎无效。但我甚至不知道它说的是什么证书。你确定在本地运行时没有使用开发存储吗?