开发者

WinInet InternetSetOption with INTERNET_OPTION_SUPPRESS_BEHAVIOR option not working as expected

Hi all and thanks for taking the time to read this. I have a c# application where I wish to override the default WinInet cookie settings. The goal is that even when the system WinInet cookie privacy settings are set to Block All, within my process, cookies will still be accepted calls. Reading the documentation, it looked straightforward enough. Here's a cleaned up version of what I have:

private unsafe void SuppressWininetBehavior()
{
    int option = (int)WinInet.SuppressBehaviorFlags.INTERNET_SUPPRESS_COOKIE_POLICY;
    int* optionPtr = &option;

    bool success = WinInet.InternetSetOption(IntPtr.Zero, WinInet.InternetOption.INTERNET_OPTION_SUPPRESS_BEHAVIOR, new IntPtr(optionPtr), sizeof(int));

    if (!success)
    {
        _log.Warn("Failed in WinInet.InternetSetOption call with INTERNET_OPTION_SUPPRESS_BEHAVIOR, INTERNET_SUPPRESS_COOKIE_POLICY");
    }
}

Where WinInet.InternetSetOption is defined as:

[DllImport("wininet.dll", SetLastError = 开发者_高级运维true, CharSet = CharSet.Auto)]
[return : MarshalAs(UnmanagedType.Bool)]
public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength);

And the constants are:

WinInet.InternetOption.INTERNET_OPTION_SUPPRESS_BEHAVIOR = 81
WinInet.SuppressBehaviorFlags.INTERNET_SUPPRESS_COOKIE_POLICY = 1

The InternetSetOption call succeeds - no error.

I have also tried passing in a global internet handle returned by InternetOpen as the first parameter to the InternetSetOption call, and it makes no difference. Cookies continue to be blocked within my process.

The Reason I need to do this is that I have an embedded Flash Player ActiveX instance which makes web requests. I have successfully used other InternetSetOption calls to modify the proxy settings that Flash uses in my process. I'm testing this on Windows 7.


Try InternetSetPerSiteCookieDecision(). You'll have to sink DWebBrowserEvents2::OnBeforeNavigate and call it for each domain, but it should work.

Also, you're using the wrong flag. If you want to disable the cookie policy, use INTERNET_SUPPRESS_COOKIE_POLICY. By using the RESET flag, you're enabling the default policy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜