此 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();
}