我有 .NET 4.5.2 应用程序正在使用SmtpClient
发送电子邮件。该应用程序安装在Windows 2012 R2服务器上。当我禁用 TLS 1 和 TLS 1.1 并仅启用 TLS 1.2 时,应用程序停止发送邮件。我认为这是因为 .NET 4.5.2 不支持 v1.2。
我正在考虑以下步骤
1>在 Windows Server 上禁用 TLS 1 和 TLS 1.1,仅启用 TLS 1.2。
2>在Windows服务器上安装.NET 4.8。
3>将应用程序的目标框架更改为4.8(在csproj和web.config中)并重新编译。
4>部署应用程序。
问题
基于文档 https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls Starting with .NET Framework 4.7.1, WCF defaults to the operating system configured version
1>这仅适用于 WCF 还是 SMTP 也默认为操作系统配置的版本?
2>或者我需要明确设置版本吗System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
3>是否可以立即设置版本 TLS 1.2,并且将来 TLS 1.3 可用时应用程序应自动默认为 TLS 1.3? (无需再次更改代码)
这仅适用于 WCF 还是 SMTP 也默认为操作系统配置的版本?
No, 这适用于所有基于 SslStream 的 .NET Framework 网络 API https://learn.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.securityprotocol?view=netframework-4.8,其中包括 SMTP、HTTP 和 FTP。
或者我是否需要明确设置版本,例如 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
如果将应用程序编译为 .NET 4.7 或更高版本,则无需将值设置为System.Net.ServicePointManager.SecurityProtocol
因为它将被设置为SystemDefault
这意味着它将继承来自操作系统或系统管理员执行的任何自定义配置的默认安全协议。
是否可以立即设置版本 TLS 1.2,并且将来 TLS 1.3 可用时应用程序应自动默认为 TLS 1.3?
是的,你只需要检查是否System.Net.ServicePointManager.SecurityProtocol
设置为其他任何不是SystemDefault
(其值为0
(零)在 .NET 4.7+ 中),在这种情况下,您可以将其设置为 TLS 1.2 来覆盖它。
var securityProtocol = (int)System.Net.ServicePointManager.SecurityProtocol;
// 0 = SystemDefault in .NET 4.7+
if (securityProtocol != 0)
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)