【问题标题】:Override IE privacy settings using IInternetSecurityManager in Webbrowser control在 Webbrowser 控件中使用 IInternetSecurityManager 覆盖 IE 隐私设置
【发布时间】:2011-10-13 06:21:42
【问题描述】:

我需要在我的 C# 应用程序中为托管的 WebBrowser 控件创建自定义安全管理器。托管的 WebBrowser 控件应独立于 IE 安全和隐私设置。

问题:如果 IE 隐私设置设置为“高”,则依赖 cookie 的网站在托管的 WebBrowser 控件中无法正常运行(如果隐私设置设置为“中”,则站点可以正常运行)。

承载 WebBrowser 控件的 winform 为 GetSecurityId、MapUrlToZone 和 ProcessUrlAction 提供了以下实现。 ProcessUrlAction 被嵌入式浏览器调用,用于 ACTIVEX_RUN、SCRIPT_RUN 等 URL 操作;但它不会被任何与 cookie 相关的 url 操作调用。

有什么方法可以启用 cookie 以进行网络浏览器控制吗?还是下面的代码有问题?

private void InitBrowserSecurityData()
{
    securityID = new byte[MAX_SIZE_SECURITY_ID];

    securityID[0] = (byte)'f';
    securityID[1] = (byte)'i';
    securityID[2] = (byte)'l';
    securityID[3] = (byte)'e';
    securityID[4] = (byte)':';
    securityID[5] = 0;
    securityID[6] = 3;
    securityID[7] = 0;
    securityID[8] = 0;
    securityID[9] = 0;
}

//GetSecurityId
int IInternetSecurityManager.GetSecurityId(string pwszUrl, IntPtr pbSecurityId, ref uint pcbSecurityId, ref uint dwReserved)
{
    if (pcbSecurityId >= MAX_SIZE_SECURITY_ID)
    {
        Marshal.Copy(securityID, 0, pbSecurityId, MAX_SIZE_SECURITY_ID);
        pcbSecurityId = 9;
        return HResults.S_OK;
    }
    return (int)WinInetErrors.INET_E_DEFAULT_ACTION;
}

//MapUrlToZone
int IInternetSecurityManager.MapUrlToZone(string pwszUrl, out uint pdwZone, uint dwFlags)
{
    pdwZone = (uint)tagURLZONE.URLZONE_LOCAL_MACHINE;
    return HResults.S_OK;
}

//ProcessUrlAction
int IInternetSecurityManager.ProcessUrlAction(string pwszUrl, uint dwAction, IntPtr pPolicy, 
    uint cbPolicy, IntPtr pContext, uint cbContext, uint dwFlags, uint dwReserved)
{
    URLACTION action = (URLACTION)dwAction;

    bool hasUrlPolicy = (cbPolicy >= unchecked((uint)Marshal.SizeOf(typeof(int))));
    URLPOLICY urlPolicy = (hasUrlPolicy) ? (URLPOLICY)Marshal.ReadInt32(pPolicy) : URLPOLICY.ALLOW;

    bool hasContext = (cbContext >= unchecked((uint)Marshal.SizeOf(typeof(Guid))));
    Guid context = (hasContext) ? (Guid)Marshal.PtrToStructure(pContext, typeof(Guid)) : Guid.Empty;
    //all URL actions are allowed
    if (hasUrlPolicy)
    {
        urlPolicy = URLPOLICY.ALLOW;
        Marshal.WriteInt32(pPolicy, (int)urlPolicy);
        return HResults.S_OK;
    }
    return (int)WinInetErrors.INET_E_DEFAULT_ACTION;
}

我已经看到了这些问题,但它们对我不起作用。

Security Level for WebBrowser control

Custom IInternetSecurityManager not being called with dialogs

overriding GetSecurityId in IInternetSecurityManager

【问题讨论】:

  • 我也遇到了类似的问题。你的问题能解决吗?
  • 抱歉,Birk 回复晚了。看起来 Cookie 操作永远不会传递给 IInternetSecurityManager...看看this

标签: c# browser


【解决方案1】:

似乎 Internet Explorer 没有将 Cookie 操作传递给 IInternetSecurityManager。这就是在嵌入式浏览器控件中难以覆盖 IE 隐私设置的原因。早在很久以前,一些聪明人就已经想到了这一点here

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 2014-10-15
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 2011-12-14
    • 2015-07-16
    相关资源
    最近更新 更多