我選擇的解決方案是調用我需要的每個上下文的初始化。它可能存在更好的解決方案,所以我打算改進我的。
首先,我定義:
public class Bootstrapper
{
private static readonly object ensureInitializationField = null;
static Bootstrapper()
{
// REFERENCE: enable TLS 1.2
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
}
/// <summary>
/// Invokes the code in the static constructor.
/// </summary>
/// <remarks>
/// Code in the static constructor is called only once.
/// </remarks>
public static void EnsureInitialization()
{
Equals(ensureInitializationField, null);
}
}
後來我喜歡這個稱呼它從所需的環境下(例如Global.asax.cs中):
Bootstrapper.EnsureInitialization();
你找到了一個解決方案? – NickG
我已經發布了我的解決方案。我希望它能爲你提供一些線索。 – Kalitsov