How can i do in C#/Windows7 , that my app do not reuse existing SSL conenction. Actually when i make a get request with HttpWebRequest to a https page if there is an existing conenction then it use this connection (= same ssl-sessionid). I have done some test and windows 7 renegotiate the ssl connection after 2 minutes . But i will that it never reuse existing connection.
i have tried a lot of things:
keep-alive, ClientCacheTime (regedit), ServicePointManager.SetTcpKeepAlive …
Thanks very much !
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();
Since you don’t provide much detail just some general pointers:
ServicePointManager.DnsRefreshTimeoutto a very low value (default is 2 minutes = 120000 ms)HttpWebRequest.ConnectionGroupNameto a unique value on EVERY requestHttpWebRequest.ServicePoint.CloseConnectionGroupwith that value AFTER EVERY requestHttpWebRequest.AbortAFTER EVERY requestThe above might work unreliably – depending on OS version and Framework version…
I am curious: achieving this means you have alot less performance… what is the goal ?