XBAP应用程序中的WebBrowser控件:允许cookie

时间:2012-11-07 10:41:15

标签: c# internet-explorer webbrowser-control session-cookies xbap

我在XBAP应用程序中有一个WebBrowser控件(System.Windows.Forms.WebBrowser + WindowsFormsHost)。问题是当我“导航()”到需要cookie的网站并且我放置了我的凭据时,WebBrowser没有在GET(HTTP)方法的“Cookie”属性中设置“session”数字参数,并且登录失败。我怀疑WebBrowser不接受cookie(或会话cookie?)。我尝试以这种方式使用IInternetSecurityManager:

    public static bool TryAllowCookies(Uri uri)
    {
        IInternetSecurityManager securityManager = (IInternetSecurityManager)new InternetSecurityManager();
        int policy = 0;
        Guid context = Guid.Empty;

        int hr = securityManager.ProcessUrlAction(uri.ToString(),
                                     URLACTION_COOKIES_SESSION | URLACTION_COOKIES_ENABLED | URLACTION_COOKIES |
                     URLACTION_COOKIES_SESSION_THIRD_PARTY | URLACTION_COOKIES_THIRD_PARTY,
                     ref policy,
                     Marshal.SizeOf(policy),
                     ref context,
                     Marshal.SizeOf(context),
                     PUAF_DEFAULT, 0);

                     return (hr == 0) && policy == URLPOLICY_ALLOW;
    }

ProcessUrlAction returs始终为True,但不起作用。

我没有找到如何将IInternetSecurityManager与WebBrowser控件一起使用的完整示例。 相反,在Windows窗体应用程序中,相同的控件可以正常工作。

HTTP嗅探:

来自XBAP应用程序的WEBBROWSER(不工作):

GET /cgi-bin/xxx.xxx HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-xpsdocument, application/x-ms-application, application/x-ms-xbap, application/xaml+xml, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, */*
Referer: http://xxx.xxx.xxx.xxx/cgi-bin/yyy.yyy
Accept-Language: it
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0E; .NET4.0C; InfoPath.2)
Host: xxx.xxx.xxx.xxx
Connection: Keep-Alive
Cookie: language=it; user=smith

WEBBROWSER来自WINDOWS表单应用程序(工作)

GET /cgi-bin/xxx.xxx HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-xpsdocument, application/x-ms-application, application/x-ms-xbap, application/xaml+xml, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, */*
Referer: http://xxx.xxx.xxx.xxx/cgi-bin/yyy.yyy
Accept-Language: it
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0E; .NET4.0C; InfoPath.2)
Host: xxx.xxx.xxx.xxx
Connection: Keep-Alive
Cookie: language=en; user=smith; session=2a9cffb0babea74e3432fc9805470faa; current_page=
谢谢你, 的Riccardo

0 个答案:

没有答案