问题: 在我们的组织中,我们有一个自行开发的单点登录应用程序,用c#/ .Net2编写,已经工作了多年。我们最近发现该应用程序无法与Outlook Web Access 2010一起使用。一些网络搜索发现了SSO供应商(Novell KB和Citrix KB)中涉及该问题的几篇文章。 OWA2010在提交时执行javascript,添加一个名为“PBack = 0”的cookie,如果不包含在帖子中,将导致身份验证失败。
问题: 如何在SHDocVw.InternetExplorer的Navigate方法中包含cookie?
//ie2 is the instance of IE (SHDocVw.InternetExplorer) containing the OWA login page
ie2.Navigate(URLToPostTo, ref vFlags, ref vTarget, ref vPost, ref vHeaders);
答案 0 :(得分:1)
此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();
}