I have a unique problem where I need a copy of IE to do some session management and run some JavaScript on the page. The goal is to retrieve a value representing the server side session ID written by the JavaScript into the HTML response.
The code looks like this:
public class RemoteFileProcessor
{
#region Fields (1)
private bool _navigating;
#endregion Fields
#region Methods (2)
public string GetSessionID(string URL)
{
string action = "";
int count = 0;
object nullObj = null;
object url = URL;
//Create an instance of IE
SHDocVw.InternetExplorerClass ie = new SHDocVw.InternetExplorerClass();
// Load the page from which to retrive the server side session identifier.
_navigating = true;
ie.DocumentComplete += ie_DocumentComplete;
ie.Navigate2(ref url, ref nullObj, ref nullObj, ref nullObj, ref nullObj);
// Wait while the page loads.
while (_navigating && count <= 30)
{
System.Threading.Thread.Sleep(1000);
count++;
}
// Get the form object from the page.
mshtml.IHTMLDocument3 doc = (mshtml.IHTMLDocument3)ie.Document;
mshtml.IHTMLElementCollection formElements = doc.getElementsByName("selectableHourlyLMPForm");
System.Collections.IEnumerator enumerator = formElements.GetEnumerator();
// Get the form action, which includes the JSessionID
while (enumerator.MoveNext())
{
mshtml.IHTMLFormElement form = (mshtml.IHTMLFormElement)enumerator.Current;
action = form.action;
}
ie.Quit();
return action;
}
// Private Methods (1)
private void ie_DocumentComplete(object pDisp, ref object URL)
{
_navigating = false;
}
#endregion Methods
}
When I run the above code in unit test on my XP machine it all works flawlessly.
When I run the code from a web service on our Win2k3 server from IIS under a service user, the internet explorer instance simply times out (takes 4-5 minutes) after the call to InternetExplorerClass.Navigate2().
Any solution would be welcome as I am at a complete loss for words on what is going on here...