c# - 使用 C# 创建 Azure 存储帐户抛出异常 "The request was aborted: Could not create SSL/TLS secure channel."

标签 c# ssl azure-storage

我的 asp.net mvc 5 应用程序中有一个方法使用 Microsoft Azure 客户端类 (CloudContext.Clients) 创建 StorageManagementClient。需要证书进行身份验证,因此我创建了一个自签名证书。

在开发机器上一切正常。

在 azure 虚拟机(windows server 2008 r2)上,我按预期导入了代码找到的证书,但是当创建 StorageManagementClient 的代码执行时抛出异常

Inner Exception Type: System.Net.WebException Inner Exception: The request was aborted: Could not create SSL/TLS secure channel. Inner Source: System Inner Stack Trace: at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) Exception Type: System.Net.Http.HttpRequestException Exception: An error occurred while sending the request. Source: test Stack Trace: at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Microsoft.WindowsAzure.StorageAccountOperationsExtensions.Create(IStorageAccountOperations operations, StorageAccountCreateParameters parameters) at ApplicationPortal.Code.DeployAzureResources.CreateStorageAccount(SubscriptionCloudCredentials credentials, String storageName) in C:\Users\DEVSYS1\Documents\Visual Studio 2017\Projects\PaSeaPortal\ApplicationPortal\Code\DeployAzureResources.cs:line 106 at ApplicationPortal.Controllers.AccountController.d__21.MoveNext() in C:\Users\DEVSYS1\Documents\Visual Studio 2017\Projects\PaSeaPortal\ApplicationPortal\Controllers\AccountController.cs:line 355

在事件查看器上我看到这个错误“生成了以下致命警报:80。内部错误状态为 301。”

最佳答案

I have imported the certificate which is found by the code as expected

您的意思是您已经在 Azure 虚拟机上安装 selfsigned .cer 证书? 如果不是这种情况,请尝试从您的开发机器导出证书并将其安装在 azure 虚拟机上。并尝试使用下面的代码再次测试它。

public static X509Certificate2 GetCert(string thumbprint)
        {

            X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            certStore.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
            if (certCollection.Count <= 0) return null;
            X509Certificate2 cert = certCollection[0];
            return cert;
        }


 var thumbprint= "cert thumbprint";
 SubscriptionCloudCredentials credentials = new CertificateCloudCredentials("subscription Id", cert);
 StorageManagementClient storageManagementClient = new StorageManagementClient(credentials);
 storageManagementClient.StorageAccounts.Get("storage name"); //only classical storage can be got.

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Hyak.Common" version="1.0.2" targetFramework="net462" />
  <package id="Microsoft.Azure.Common" version="2.0.4" targetFramework="net462" />
  <package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Bcl" version="1.1.9" targetFramework="net462" />
  <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net462" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net462" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net462" />
  <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net462" developmentDependency="true" />
  <package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net462" />
  <package id="Microsoft.WindowsAzure.Common" version="1.4.1" targetFramework="net462" />
  <package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.1" targetFramework="net462" />
  <package id="Microsoft.WindowsAzure.Management.Storage" version="6.0.1" targetFramework="net462" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net462" />
</packages>

如果您尝试创建资源管理存储帐户,请尝试使用Microsoft.Azure.Management.Fluent SDK .我们还可以从 github 获得更多演示代码

关于c# - 使用 C# 创建 Azure 存储帐户抛出异常 "The request was aborted: Could not create SSL/TLS secure channel.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44412099/

相关文章:

android - HostNameVerifier Android 应用商店

c# - 如何在Azure表存储中使用整数RowKey?

c# - DataGridView 列只有一些条目的按钮?

c# - 根据 XML 元素的值创建 if 语句 block

excel - 如何覆盖网站安全证书以消除错误?

c# - Azure存储1.7 : how to make a simple select that works everytime?

shell - 使用 wget 下载文件时如何仅使用文件名保存文件

c# - 如何以 TZ 格式检索系统时区.net c#

c# - 在不实现 IXmlSerializable 的情况下序列化只读集合

java - Jboss7 上的 COMODO SSL 证书