I need to enable cookies in my WPF application WebBrowser control even if it is disabled in the IE settings.
After going through many questions this is what i tried, but this does not work.
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, ref int flag, int dwBufferLength);
static bool EnableCookies(int settingCode, int option)
{
if (!InternetSetOption(IntPtr.Zero, settingCode, ref option, sizeof(int)))
{
var ex = Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
//throw ex;
return false;
}
return true;
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
EnableCookies(81, 1);
}
If this is not possible, I wish to at least be able to get the setting value to show the user an error message that cookies are not enabled.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…