相关疑难解决方法(0)

如何让ASP.NET访问证书存储区中的证书中的私钥?

我有一个ASP.NET应用程序访问证书存储区中的证书中的私钥.在Windows Server 2003上,我能够使用winhttpcertcfg.exe来授予对NETWORK SERVICE帐户的私钥访问权限.如何授予访问IIS 7.5网站中Windows Server 2008 R2上的证书存储(本地计算机\个人)中的证书中的私钥的权限?

我尝试使用证书MMC(Server 2008 R2)为"Everyone","IIS AppPool\DefaultAppPool","IIS_IUSRS"以及我能找到的每个其他安全帐户提供完全信任访问权限.但是,下面的代码演示了代码无法访问使用私钥导入的证书的私钥.每次访问私钥属性时,代码都会抛出并抛出错误.

Default.aspx的

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="repeater1" runat="server">
            <HeaderTemplate>
                <table>
                    <tr>
                        <td>
                            Cert
                        </td>
                        <td>
                            Public Key
                        </td>
                        <td>
                            Private Key
                        </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                    <%#((X509Certificate2)Container.DataItem).GetNameInfo(X509NameType.SimpleName, false) %>
                    </td>
                    <td>
                    <%#((X509Certificate2)Container.DataItem).HasPublicKeyAccess() %>
                    </td>
                    <td>
                    <%#((X509Certificate2)Container.DataItem).HasPrivateKeyAccess() %>
                    </td>
                </tr> …

asp.net certificate winhttp iis-7.5

108
推荐指数
5
解决办法
15万
查看次数

.NET Framework 4.0中的TLS 1.2

我有一台运行十几个.NET Framework 4.0 WebForms应用程序的Windows Server 2008 R2服务器,我需要禁用TLS 1.0及更低版本.当我这样做时,所有安全连接都失败了,我被迫重新启用TLS 1.0.有没有办法在框架4.0环境中使用TLS 1.2?也许我错过了什么?

此外,由于我们使用的CMS版本的限制,我们目前无法升级Framework.

asp.net .net-4.0 windows-server-2008-r2 tls1.2

62
推荐指数
6
解决办法
9万
查看次数

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

我的客户通过他们的SSL和Internet Explorer了解了我的问题.他们说他们在访问URL时会遇到信任问题.

我通过HTTPS访问JSON.该网站位于一台服务器上,我在本地计算机上使用控制台应用程序.我试图绕过SSL证书,但是,我的代码仍然失败.

我可以改变HttpWebRequest来解决这个问题吗?

我使用此代码得到此错误:

    // You must change the URL to point to your Web server.
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "GET";
        req.AllowAutoRedirect = true;

        // allows for validation of SSL conversations
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


        WebResponse respon = req.GetResponse();
        Stream res = respon.GetResponseStream();

        string ret = "";
        byte[] buffer = new byte[1048];
        int read = 0;
        while ((read = res.Read(buffer, 0, buffer.Length)) > 0)
        {
            //Console.Write(Encoding.ASCII.GetString(buffer, 0, read));
            ret += Encoding.ASCII.GetString(buffer, 0, read);
        } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net ssl httpwebrequest

56
推荐指数
5
解决办法
12万
查看次数

根据请求在.net HttpWebRequest上设置SecurityProtocol(Ssl3或TLS)

我的应用程序(.net 3.5 sp1)使用HttpWebRequest与不同的端点进行通信,有时它使用HTTPS,其中每个托管服务器可能具有不同的安全协议要求,例如TLS或SSL3或其中之一.

通常,服务器可以很好地和愉快地协商/回退SecurityProtocol使用TLS或SSL3,但有些则没有,当.net被设置为TLS或SSL3(我认为默认)那些仅支持SSL3的服务器会导致.net抛出发送错误.

据我所知,.net为ServicePointManager对象提供了一个属性SecurityProtocol,可以将其设置为TLS,SSL3或两者.因此理想情况下,当设置为两个想法是客户端和服务器应该协商使用什么,但如前所述似乎不起作用.

据说你可以设置ServicePointManager.SecurityProtocol = Ssl3但是那些想要使用TLS的端点呢?

我在ServicePointManager和SecurityProtocol中看到的问题是它的静态和应用程序域范围.

那么问题..

我将如何使用不同的SecurityProtocol来使用HttpWebRequest,例如

1)url 1设置为使用TLS | Ssl3(谈判)

2)url 2设置为Ssl3(仅限Ssl3)

.net httpwebrequest

32
推荐指数
3
解决办法
4万
查看次数

每个请求更改安全协议(HttpClient)

我有一个Web API,必须与几个不同的服务进行通信.目前,我将Web API设置为使用以下安全协议:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

当API通过HttpClient(比如Twitter)调用另一个服务时,它将使用该协议.然而,与此同时,另一个请求可能会从云访问某些内容,无论出于何种原因,目前需要TLS(而不是TLS 1.2).在发出之前,对云的请求再次设置安全协议:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

我遇到的问题是当两个独立且唯一的请求进入时,一个用于Twitter,一个用于云,安全协议可能在发送之前切换到"错误的",导致请求失败.

有没有办法在HttpClient每个请求上设置安全协议,这样我就不会在某个单独的某个地方交换设置?

c# ssl http asp.net-web-api

15
推荐指数
2
解决办法
9828
查看次数

无法创建SSL/TLS安全通道 - 问题可能是代理服务器吗?

我有一个ac#app,它调用一个使用证书进行身份验证的Web服务方法.代码有效,因为当它安装在服务器A(没有代理)时,它会进行身份验证.

当我在服务器B上安装代码时,在客户端站点上,它安装在代理服务器后面.我真的尝试了几乎所有的东西,但我一直收到这个错误:

无法创建SSL/TLS安全通道

您是否认为此问题可能是由代理服务器引起的?如果您有任何亲身经历,请分享.

谢谢

c# web-services certificate

14
推荐指数
3
解决办法
4万
查看次数

无法创建SSL/TLS安全通道适用于winforms但不适用于asp.net

我有一个Web服务,我通过"添加服务参考"注册,需要HTTPS和证书.下面是我实例化我的服务的代码:

        service = new MyReferencedWebService();

        X509Certificate2 cert = new X509Certificate2();

        var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Mycert.cer");
        var bytes = new byte[stream.Length];

        stream.Read(bytes, 0, bytes.Length);

        cert.Import(bytes, MYPASSWORD, X509KeyStorageFlags.DefaultKeySet);

        service.ClientCredentials.ClientCertificate.Certificate = cert;
Run Code Online (Sandbox Code Playgroud)

我的配置看起来像这样:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="RecordGeneratorWebServiceSoapHttp">
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://mywebserviceurl"
            binding="basicHttpBinding" bindingConfiguration="RecordGeneratorWebServiceSoapHttp"
            contract="MyService.RecordGeneratorWebServiceInterface"
            name="RecordGeneratorWebServicePort" />
    </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

如果我创建一个简单的winforms .exe并使用上面的代码,我会收到来自我的Web服务的响应.但是,如果我在ASP.NET中使用相同的代码,我会得到以下内容:

请求已中止:无法创建SSL/TLS安全通道.

如何在ASP.NET中完成这项工作?

编辑: 我应该补充.我使用的客户端证书与智能卡绑定,需要输入PIN才能使用.不确定这是否有所不同.

当客户端登录到应用程序时,它会提示他们输入证书PIN.在这种情况下,他们将CAC卡插入CAC阅读器.那么也许我可以以某种方式使用Request.ClientCertificate?

c# asp.net ssl web-services

13
推荐指数
1
解决办法
4087
查看次数

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

可能重复:
请求已中止:无法创建SSL/TLS安全通道

我正在尝试发送带有客户端证书的http请求.该文件,在本例中是一个 .p12文件.但是当它到达该行时,responseStream = httpRequest.GetRequestStream();它会抛出WebException:System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

我在IIS7.5(在Windows 7上)上调试它,其中应用程序池标识是"LocalSystem".

我该如何解决这个问题?

        System.IO.Stream responseStream = null;
        string errorString = string.Empty;
        ;
        string postData = string.Empty;
        HttpWebRequest httpRequest = null;
        System.Text.Encoding Encoding = new System.Text.UTF8Encoding();
        try
        {
            XmlDocument orderXml = new XmlDocument();
            orderXml.Load(@"c:\xmlfile.xml");
            postData = orderXml.InnerXml;

            byte[] byte1 = Encoding.GetBytes(postData);

            httpRequest = (HttpWebRequest)WebRequest.Create("https://testurl.com/SOAP_v1_0/");
            httpRequest.Method = "POST";
            httpRequest.Timeout = 9000;
            httpRequest.KeepAlive = false;
            httpRequest.ContentType = "text/xml; charset=" + "utf-8";
            httpRequest.ContentLength = …
Run Code Online (Sandbox Code Playgroud)

c# httpwebrequest x509certificate2

12
推荐指数
1
解决办法
3万
查看次数

无法创建SSL/TLS安全通道.SecureChannelFailure

使用SSL证书进行SOAP调用时出现SSL错误:

请求已中止:无法创建SSL/TLS安全通道.

奇怪的是,如果我在Firefox中加载证书并访问端点或调用API而不发送任何数据,我不会收到任何错误消息并且连接成功.暴露API的公司也提到证书是犹太人的.

我正在加载的证书具有"Everyone"的完全权限.我已经尝试过我在互联网上看到的所有解决方案,但仍然遇到错误.

这是我创建请求的代码:

 ServicePointManager.Expect100Continue = true;
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 var request = (HttpWebRequest)WebRequest.Create(plugin.EndPoint);
 request.ContentType = "text/xml; charset=utf-8";
 request.Method = "POST";
Run Code Online (Sandbox Code Playgroud)

获取证书的代码(我也尝试过使用pfx):

var cert = new 
 509Certificate2(@"C:\clientcert.p12", "FakePassword");
request.ClientCertificates.Add(cert);
Run Code Online (Sandbox Code Playgroud)

和请求的代码:

  byte[] byteArray = Encoding.UTF8.GetBytes(xml);
    request.ContentLength = byteArray.Length;
    using (var dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();


                    using (WebResponse response = request.GetResponse())
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            StreamReader reader = 
new StreamReader(responseStream ?? throw new InvalidOperationException());
                            return reader.ReadToEnd();
                        }
                    }

                }
Run Code Online (Sandbox Code Playgroud)

编辑:

以下是运行请求的跟踪输出:

System.Net信息:0:[11844] InitializeSecurityContext(In-Buffers count = …

.net c#

9
推荐指数
1
解决办法
2万
查看次数

请求已中止:无法创建SSL/TLS安全通道,但可以使用浏览器/ POSTMAN

我有点迷失在这里.添加ServicePointManager的东西通常会解决这个问题,但这次我不断收到错误.我的服务器可以从浏览器和POSTMAN访问相同的URL.但是通过网站运行这个失败了.这虽然适用于我的本地计算机.我在服务器上启用了TLS 1.1和TLS 1.2.

我的服务器TLS设置有什么问题吗?https://www.ssllabs.com/ssltest/analyze.html?d=basketball.exposureevents.com

我使用的是CertifyTheWeb证书,基本上是免费的SSL.不确定这是否与它有关.

我发送到下面的链接,从IIS下面的代码作出拒绝请求.

https://www.nationalsportsid.com/tournament/6028

消息:请求已中止:无法创建SSL/TLS安全通道.来源:系统堆栈跟踪:在System.Net.HttpWebRequest.GetResponse()处

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

var webRequest = (HttpWebRequest) WebRequest.Create("https://www.nationalsportsid.com/tournament/" + nationalSportsId);
try
{
    using (var webResponse = (HttpWebResponse) webRequest.GetResponse())
    {
        if (webResponse.StatusCode == HttpStatusCode.OK)
        {
            return true;
        }
    }
}
catch (WebException ex)
{
    Logger.Error(ex);
}
Run Code Online (Sandbox Code Playgroud)

这是Message Analyzer记录的内容

握手

在此输入图像描述

警报

在此输入图像描述

.net c# ssl https

9
推荐指数
1
解决办法
702
查看次数