Cross Domain Silverlight XAP Access in Silverlight 2

I'm starting to get to grips with Silverlight and the first thing I wanted to do was fetch a xap file from a different host to that which was serving up the page.In other words, a page retrieved from somehost containing a Silverlight object tag with source attribute equal to http://someotherhost/somesite/silverlightcontrol.xap.Note the following points applicable to cross domain access:

  • Unlike the case where your xap file is served up from the same host, the Silverlight runtime checks the MIME type in the HTTP header of your xap content when it has been served up from a different host.  So make sure that it is correctly set to application/x-silverlight-app (not application/x-silverlight-2 - which wasted a good couple of hours of my time).  If you don't set it correctly you'll see the Silverlight runtime fetch the file (if you're spying in Fiddler or suchlike), then a great big nothing will happen.
  • If you want to access the DOM on the page containing the control from within your control's code you'll need to set the enableHtmlAccess attribute to true in the object tag.
  • If you want to access scriptable types in your control's code from JavaScript you will need to add the ExternalCallersFromCrossDomain attribute to the control's manifest and set it to ScriptableOnly.  Note, however that you won't be able to subscribe to control events such as onload.