如果需要編程實現IE選項中清除SSL狀態的功能,可用SslEmptyCache函數,SslEmptyCache函數定義在Schannel.dll中,採用動態連結即可。
代碼如下:
using System;
using System.Runtime.InteropServices;
namespace Demo
{
public class Ssl
{
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(String dllname);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, String procname);
internal delegate bool SslEmptyCacheHelper(IntPtr targetName, int flags);
/// <summary>
/// UNICODE版
/// </summary>
/// <returns></returns>
public bool SslEmptyCacheW()
{
IntPtr schannel = LoadLibrary("Schannel.dll");
IntPtr procaddr = GetProcAddress(schannel, "SslEmptyCacheW");
SslEmptyCacheHelper helper = (SslEmptyCacheHelper)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(SslEmptyCacheHelper));
return helper(IntPtr.Zero, 0);
}
/// <summary>
/// ANSI版
/// </summary>
/// <returns></returns>
public bool SslEmptyCacheA()
{
IntPtr schannel = LoadLibrary("Schannel.dll");
IntPtr procaddr = GetProcAddress(schannel, "SslEmptyCacheA");
SslEmptyCacheHelper helper = (SslEmptyCacheHelper)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(SslEmptyCacheHelper));
return helper(IntPtr.Zero, 0);
}
}
}
參考資料:
1、SslEmptyCache Function
2、.NET 2.0 中 GetDelegateForFunctionPointer 函數實現原理淺析 [草稿]