views:

22

answers:

1

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.

A: 

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.

jeffamaphone
Thanks for the answer. My question contained a mistake due to me experimenting with the different flag values. INTERNET_SUPPRESS_COOKIE_POLICY also appears to have no effect.I'd prefer not to use InternetSetPerSiteCookieDecision(), as I don't want to change the user's settings. The INTERNET_OPTION_SUPPRESS_BEHAVIOR seems like the ideal solution, as it just affects the current process...if it would work.
Ross