使用 Azure 服务管理 API 连接时出现证书问题

发布于 2024-10-30 19:52:59 字数 1503 浏览 4 评论 0 原文

我在获取托管服务列表时遇到问题。我的代码如下:

 string requestUrl = "https://management.core.windows.net/" + SubscriptionID + "/services/hostedservices";

        string ReturnBody = string.Empty;
        WebResponse resp = null;
        try
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            NameValueCollection RequestHeaders = new NameValueCollection();
            RequestHeaders.Add("x-ms-version", x_ms_version);
            X509Certificate cert = X509Certificate.CreateFromCertFile(CertificatePath);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            request.Method = "GET";
            request.ClientCertificates.Add(cert);
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            if (RequestHeaders != null)
                request.Headers.Add(RequestHeaders);
            resp = request.GetResponse();              
        }
        catch (WebException webEx)
        {
            //ERROR: The request was aborted: Could not create SSL/TLS secure channel.” error.
        }
        catch (Exception excep)
        {
            
        }
        finally
        {
            if (resp != null) { resp.Close(); }
            resp = null;
        }  

运行上面的代码时我得到:

“请求被中止:无法创建 SSL/TLS 安全通道”

一个奇怪的问题是,相同的代码在我的一个 WPF 应用程序中工作正常,但在 Web 应用程序中出现错误。 因此,这可能是 IIS 安全问题,我尝试向每个人授予该文件夹的权限,但没有成功。

I am getting an issue while fetching the list of hosted services. My code is as below:

 string requestUrl = "https://management.core.windows.net/" + SubscriptionID + "/services/hostedservices";

        string ReturnBody = string.Empty;
        WebResponse resp = null;
        try
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            NameValueCollection RequestHeaders = new NameValueCollection();
            RequestHeaders.Add("x-ms-version", x_ms_version);
            X509Certificate cert = X509Certificate.CreateFromCertFile(CertificatePath);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            request.Method = "GET";
            request.ClientCertificates.Add(cert);
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            if (RequestHeaders != null)
                request.Headers.Add(RequestHeaders);
            resp = request.GetResponse();              
        }
        catch (WebException webEx)
        {
            //ERROR: The request was aborted: Could not create SSL/TLS secure channel.” error.
        }
        catch (Exception excep)
        {
            
        }
        finally
        {
            if (resp != null) { resp.Close(); }
            resp = null;
        }  

While running above code I am getting:

"The request was aborted: Could not create SSL/TLS secure channel"

One strange point regarding this is that same code is working fine in one of my WPF application, but giving an error in Web Application.
So, it may issue of IIS security, I have made unsuccessful attempt by giving permission to everyone for that folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒路情人 2024-11-06 19:52:59

我相信我在 MSDN 论坛上回答了这个问题: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/5e6a2cfd-c2b6-4880-a79c-4bf39f4d7ca8/#b427afb6-d68f-4591-8466-870e791b43c9

你尝试过我的建议吗 制成?之后您遇到的错误是什么。

高拉夫

I believe I responded to this question on MSDN forums: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/5e6a2cfd-c2b6-4880-a79c-4bf39f4d7ca8/#b427afb6-d68f-4591-8466-870e791b43c9

Did you try out the suggestion I made? What's the error you're getting even after that.

Gaurav

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文