带有 INTERNET_OPTION_SUPPRESS_BEHAVIOR 选项的 WinInet InternetSetOption 未按预期工作

发布于 2024-09-07 01:28:02 字数 1414 浏览 10 评论 0原文

大家好,感谢您花时间阅读本文。我有一个 ac# 应用程序,我希望覆盖默认的 WinInet cookie 设置。目标是,即使系统 WinInet cookie 隐私设置设置为“全部阻止”,在我的进程内,cookie 仍将被接受调用。阅读文档,它看起来很简单。这是我所拥有的内容的清理版本:

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");
    }
}

其中 WinInet.InternetSetOption 定义为:

[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);

常量为:

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

InternetSetOption 调用成功 - 没有错误。

我还尝试将 InternetOpen 返回的全局互联网句柄作为 InternetSetOption 调用的第一个参数传递,这没有什么区别。 Cookie 在我的进程中继续被阻止。

我需要这样做的原因是我有一个嵌入式 Flash Player ActiveX 实例,它可以发出 Web 请求。我已成功使用其他 InternetSetOption 调用来修改 Flash 在我的进程中使用的代理设置。我正在 Windows 7 上测试这个。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不语却知心 2024-09-14 01:28:02

尝试 InternetSetPerSiteCookieDecision()。您必须接收 DWebBrowserEvents2::OnBeforeNavigate 并为每个域调用它,但它应该可以工作。

另外,您使用了错误的标志。如果要禁用 cookie 策略,请使用 INTERNET_SUPPRESS_COOKIE_POLICY。通过使用 RESET 标志,您可以启用默认策略。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文