How to access a Silverlight XAP file through a domain?

I am trying to add a Silverlight application that lives on one subdomain to a webpage in another subdomain. For some reason this just doesn't work ... my Silverlight application loads as such at http://subA.domain.com/somepage.html :

<div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="800px" height="600px"> <param name="source" value="http://subB.domain.com/SilverlightApp.xap" /> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="2.0.31005.0" /> <param name="autoUpgrade" value="true" /> <param name="enableHtmlAccess" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /> </a> </object> <iframe style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe> </div> 

If I translate SilverlightApp.xap to subA.domain.com, it will load fine. What steps are required to access the XAP file across domains? I cleaned the net, trying to figure it out and it seems like I'm not going anywhere.

Thanks!!

+7
silverlight cross-domain
source share
3 answers

When Silverlight requests the cross-domain of an .XAP file, the content type should be: application / x-silverlight-app . In addition, you need a cross-domain policy file in another domain. GL

+2
source share

To help others who have this problem and don’t want to use IFrames, see the link as it solved my problem. Despite the fact that the author refers to Silverlight 2, he solved my problem in Silverlight 3. In case the link goes down, there are two things that I need to do:

- In the Silverlight application, edit AppManifest.xml to add the following:

 <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ExternalCallersFromCrossDomain="ScriptableOnly"> 

- If you use HtmlPage in your Silverlight application (for example, when reading the QueryString submitted to the hosting page), you should also add:

 <param name="enableHtmlAccess" value="true" /> 

silverlight object on the hosting page.

Please note that this is due to security implications, and I cannot help but think that is why Microsoft is not going to distribute this information. However, in my case, I do not have the Silverlight elements available for scripting, and since I wrote the silverlight application, I have no problems with the hosting page that allows the Silverlight application to be available to it.

While studying this issue, I noticed that this problem and the corresponding solutions are confused with a separate problem - the silverlight xap problem accessing the wcf service across domain boundaries. This problem requires the clientaccesspolicy.xml file located in the root directory of the website hosting the wcf service.

Thus, it is possible for the 1st site to access the xap file on the 2nd site, which accesses the data service on the third site, for maximum flexibility and reuse.

+5
source share

You can create a simple html file next to the .xap that contains the silverlight object and access it from the iframe. Here is how http://silverlight.live.com/ fixed this problem, for example.

On the main page at subA.domain.com, add an iframe that displays the html page in another domain:

 <iframe src="http://subB.domain.com/SilverlightApp.html" scrolling="no" frameborder="0" style="width:800px;height:600px"> </iframe> 

and SilverlightApp.html on subBdomain.com might look something like this:

 <html> <body> <div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="800px" height="600px"> <param name="source" value="http://subB.domain.com/SilverlightApp.xap" /> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="2.0.31005.0" /> <param name="autoUpgrade" value="true" /> <param name="enableHtmlAccess" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /> </a> </object> <iframe style='visibility: hidden; height: 0; width: 0; border: 0px'> </iframe> </div> </body> </html> 
0
source share

All Articles