Hi @S Abijith , Welcome to Microsoft Q&A,
You can control session resumption by ensuring that TLS sessions are not cached. In .NET Framework 4.8, you can use ServicePointManager
or HttpClientHandler
to configure the connection behavior.
Disable session caching by overriding the ServicePointManager
setting.
Use SslProtocols
to specify only TLS protocols that do not have a session resumption mechanism (for example, TLS 1.2 or 1.3).
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.CheckCertificateRevocationList = true;
To ensure the full handshake only happens once:
- Use
HttpClient
orHttpWebRequest
to establish a connection with the server and perform a single HTTPS request. - The first request will perform a full handshake as part of establishing the TLS connection.
Enable persistent connections to reuse the same TLS session for subsequent requests without re-establishing the handshake:
- Make sure you include the
Connection: Keep-Alive
header in your request. - Use the same
HttpClient
instance for all subsequent requests to the server. This will reuse the established connection.
var handler = new HttpClientHandler
{
UseCookies = false,
SslProtocols = System.Security.Authentication.SslProtocols.Tls12
};
var client = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(100)
};
client.DefaultRequestHeaders.Connection.Add("Keep-Alive");
Once a TLS session is established:
- Do not explicitly close the connection.
- Reuse the same connection for all subsequent commands.
- Use
ServicePoint
to monitor the connection state to ensure it remains open:
ServicePoint sp = ServicePointManager.FindServicePoint(new Uri("https://yourserver.com"));
sp.ConnectionLeaseTimeout = -1; // Keep connection alive indefinitely
sp.MaxIdleTime = 100000; // Set idle timeout
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.