首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用SHDocVw.InternetExplorer.Navigate在帖子中发送cookie?

如何使用SHDocVw.InternetExplorer.Navigate在帖子中发送cookie?
EN

Stack Overflow用户
提问于 2011-07-27 04:20:15
回答 1查看 2.6K关注 0票数 0

问题:在我们的组织中,我们有一个用c#/.Net2编写的自家开发的单点登录应用程序,已经工作了很多年。我们最近发现该应用程序无法与Outlook Web Access 2010配合使用。经过几次网络搜索,发现了一些来自单点登录供应商(Novell KBCitrix KB)的文章,这些文章都提到了这个问题。OWA2010在提交时执行一个javascript,该脚本添加一个名为“PBack=0”的cookie,如果不包含在post中,将导致身份验证失败。

问:如何在SHDocVw.InternetExplorer的导航方法中包含cookie?

代码语言:javascript
运行
复制
//ie2 is the instance of IE (SHDocVw.InternetExplorer) containing the OWA login page
ie2.Navigate(URLToPostTo, ref vFlags, ref vTarget, ref vPost, ref vHeaders);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-07 04:28:36

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

代码语言:javascript
运行
复制
 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();
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6836078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档