Adam Kinney (of Silverlight Evangelism fame) was finding some odd behavior with his new (and cool) Silverlight Powered XBox Gamercard. Of interest was the Gamertag link on the Gamercard. When you use it on his site, it works like a dream but once you put the Gamercard on a separate site the link would cause the Silvelright app to just disappear instead of navigating to XBox.com.
One note, Adam figured it out…not me.
So what is going on. Adam noticed that it worked on his site unless the subdomain was different (it was working on www.adamkinney.com but not adamkinney.com). It turned out that the issue was that **enableHtmlAccess **was not enabled. This is a great case where Adam should have used HtmlPage.IsEnabled. In case you’re not aware, the HtmlPage.IsEnabled returns true if the Silverlight application has the right to deal with the HTML page. But how is this determined?
There are three ways to host Silverlight today:
For Adam’s needs he was using the <object> tag so that people could drop it on their blog and it would just work. By default enableHtmlAccess is false when using the <object> tag hosting method. So the fix for Adam’s problem was to add this parameter to the object tag. Go look at the Silverlight Gamertag toy if you want to see how that works.
The real issue here is consistency. I assume Adam has worked with Silverlight like I have. Lots of small to medium sized examples. Examples are cool but generally that means we’ve been creating Silverlight content but using the most simple method for hosting our examples. This means the asp:Silverlight control. This wasn’t obvious to either of us though because in both the Silverlight.js and <asp:Silverlight /> hosting method the enableHtmlAccess defaults to true…which is opposite of the <object> method.
So the lesson learned here is to use HtmlPage.IsEnabled to test to see if your particular host allows access to the HTML of the page (including support for HtmlWindow.Navigate).