Silverlight 4: IFRAME HtmlDocument is null

We are using an internal HTML-based single sign on page to authenticate users. In order to avoid reloading the Silverlight application into memory twice, we are rendering this login page inside of a dynamically generated IFRAME that Silverlight generates. This single sign on HTML page is located on a different server than our Silverlight application’s XAP file.

Silverlight will only display the IFRAME if the user is not logged in. The HTML page has some JavaScript that sets focus to the username text field. Unfortunately, it gets really angry when visibility is set to hidden.

private HtmlElement _loginFrame;

_loginFrame = HtmlPage.Document.CreateElement("iframe");
_frameWindow = _loginFrame.GetProperty("contentWindow") as HtmlWindow;
_loginFrame.AttachEvent("onload", new EventHandler<HtmlEventArgs>(OnHtmlFrameContentLoaded));

Now inside of the OnHtmlFrameContent loaded event handler I attempt to obtain a reference to the HtmlDocument object.

HtmlDocument doc = this._frameWindow.GetProperty("document") as HtmlDocument;

 

Unfortunately, doc is always null. I suspect that this is because the IFRAME is being pointed at a domain that is different than the main HTML container’s domain.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s