C# XBAP应用程序内部的WebBrowser控件:允许cookie

C# XBAP应用程序内部的WebBrowser控件:允许cookie,c#,internet-explorer,webbrowser-control,session-cookies,xbap,C#,Internet Explorer,Webbrowser Control,Session Cookies,Xbap,我在XBAP应用程序中有一个WebBrowser控件(System.Windows.Forms.WebBrowser+WindowsFormsHost)。问题是,当我“导航()”到需要Cookie的网站并放入凭据时,WebBrowser没有在GET(HTTP)方法的“Cookie”属性中设置“session”number参数,登录失败。我怀疑WebBrowser不接受Cookie(或会话Cookie?)。我尝试以以下方式使用IInternetSecurityManager: public

我在XBAP应用程序中有一个WebBrowser控件(System.Windows.Forms.WebBrowser+WindowsFormsHost)。问题是,当我“导航()”到需要Cookie的网站并放入凭据时,WebBrowser没有在GET(HTTP)方法的“Cookie”属性中设置“session”number参数,登录失败。我怀疑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(不工作):

来自WINDOWS窗体应用程序的WEBBROWSER(WORKS)

谢谢,,
Riccardo

我看不出您在哪里设置“会话”号码,我遗漏了什么?
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
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=