c# - 每次如何重新协商 SSL 连接 = 不同的 ssl-SessionID(windows,c#)

标签 c# ssl

我如何在 C#/Windows7 中做,我的应用程序不重用现有的 SSL 连接。实际上,当我使用 HttpWebRequest 向 https 页面发出获取请求时,如果存在现有连接,则它会使用此连接(= 相同的 ssl-sessionid)。我做了一些测试,Windows 7 在 2 分钟后重新协商 ssl 连接。但我希望它永远不会重用现有连接。

我已经尝试了很多东西: 保持事件状态,ClientCacheTime(注册表编辑器),ServicePointManager.SetTcpKeepAlive ...

非常感谢!

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            ServicePointManager.DnsRefreshTimeout = 200;
           /* ServicePointManager.SetTcpKeepAlive(false,0,0);
            ServicePointManager.DefaultConnectionLimit = 100;
            ServicePointManager.MaxServicePointIdleTime = 1;*/
        //    ServicePointManager.DefaultConnectionLimit = 1;
            uri = "https://server.com/test.jsp";

            HttpWebRequest request = (HttpWebRequest)
          WebRequest.Create(uri);
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)";
            request.CookieContainer = cookieJar;
            request.ContentType = "text/xml";// content type

            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version11;
            request.Method = "GET";
            request.ConnectionGroupName = "dsd" + i;
           // request.ReadWriteTimeout = 2000;
           /* request.Timeout = 5000;
            request.UseDefaultCredentials = false;
            request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
            request.ConnectionGroupName = DateTime.Now.Ticks.ToString(); */
           // X509Certificate2 cert = new X509Certificate2("C:\\a.crt", "abcd");
           X509Certificate2 cert = new X509Certificate2();
            request.ClientCertificates.Add(cert);
           /* request.PreAuthenticate = false;
            request.Pipelined = true;*/


            WebResponse rsp = request.GetResponse();
            string PageContent = new StreamReader(rsp.GetResponseStream()).ReadToEnd();


            textBox1.Text = PageContent;
            request.ServicePoint.CloseConnectionGroup("dsd" + i);
            request.Abort();

            request.ClientCertificates.Clear();
            rsp.GetResponseStream().Close();
            rsp.Close();
            request.Abort();

最佳答案

由于您没有提供太多细节,所以只提供了一些一般性的指示:

以上可能不可靠 - 取决于操作系统版本和框架版本......

我很好奇:实现这一目标意味着您的性能要低很多...目标是什么?

关于c# - 每次如何重新协商 SSL 连接 = 不同的 ssl-SessionID(windows,c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7419434/

相关文章:

c# - Razor 页面 : Does OnGet Handler "accept" a request body?

ruby-on-rails - SSL 与 Ruby on Rails

ssl - 如何绕过 Amazon 负载均衡器以终止对我的自动扩展组实例的 https 访问?

c# - DateTime.ParseExact - 如何解析具有相同格式字符串的一位数和两位数的小时数?

c# - 字段的详细 XML 文档。有可能吗?

c# - RadnumericTextbox 舍入问题

ssl - 显示公司名称而不是 "https"

c# - 使用 Linq 查询 XElement - 深入了解 XElement

ssl - 无法使用 nginx 配置 certbot 以接受 https

c# - 使用 C# 使用 Assembly GetManifestResourceStream 方法读取资源文件