如何使用SHDocVw在POST中发送cookie.InternetExplorer.导航

本文关键字:cookie InternetExplorer 导航 何使用 SHDocVw POST | 更新日期: 2023-09-27 18:03:42

问题:在我们的组织中,我们有一个用c#/编写的自制单点登录应用程序。Net2已经运行多年。我们最近发现该应用程序不适用于Outlook Web Access 2010。几次网络搜索发现了SSO供应商(Novell KB和Citrix KB(的几篇文章,其中提到了这个问题。OWA2010在提交时执行一个javascript,添加一个名为"PBack=0"的cookie,如果不包含在帖子中,将导致身份验证失败。

问题:如何在SHDocVw的Navigate方法中包含cookie。InternetExplorer?

//ie2 is the instance of IE (SHDocVw.InternetExplorer) containing the OWA login page
ie2.Navigate(URLToPostTo, ref vFlags, ref vTarget, ref vPost, ref vHeaders);

如何使用SHDocVw在POST中发送cookie.InternetExplorer.导航

此c#代码在Internet explorer中为owa 2010执行单点登录。

 AutoResetEvent documentCompleteOW2010;
    void OWA2010LaunchAndSSO()
    {
        var sURL "https://owaserver.yourorg.org/owalogon.asp?
        SHDocVw.InternetExplorer explorer = new SHDocVw.InternetExplorer();
        explorer.Visible = true;
        explorer.DocumentComplete += OnIEDocumentCompleteOWA2010; // Setting the documentComplete Event to false            
        documentCompleteOW2010 = new AutoResetEvent(false);
        object mVal = System.Reflection.Missing.Value;
        explorer.Navigate(sURL, ref mVal, ref mVal, ref mVal, ref mVal);// Waiting for the document to load completely            
        documentCompleteOW2010.WaitOne(5000);
        try
        {
            mshtml.HTMLDocument doc = (mshtml.HTMLDocument)explorer.Document;
            mshtml.HTMLInputElement userID = (mshtml.HTMLInputElement)doc.all.item("username", 0);
            userID.value = "someADUserName";
            mshtml.HTMLInputElement pwd = (mshtml.HTMLInputElement)doc.all.item("password", 0);
            pwd.value = "someADPassword";
            mshtml.HTMLInputElement btnsubmit = null;
            var yada = doc.getElementsByTagName("input");
            foreach (var VARIABLE in yada)
            {
                var u = (mshtml.HTMLInputElement)VARIABLE;
                if (u.type == "submit")
                {
                    btnsubmit = u;
                }
            }
            btnsubmit.click();
        }
        catch (Exception err)
        {
            //do something
        }
        finally
        {
            //remove the event handler
            explorer.DocumentComplete -= OnIEDocumentCompleteOWA2010;
        }
    }
    private void OnIEDocumentCompleteOWA2010(object pDisp, ref object URL)
    {
        documentCompleteOW2010.Set();
    }