Question

I'm trying to add my Silverlight application that lives on one subdomain to a web page in another subdomain. For some reason this just plain isn't working ... my Silverlight application is loaded as such in a page on 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 move SilverlightApp.xap to subA.domain.com, it loads perfectly. What steps are needed to access a XAP file across domains?? I've been scraping the net trying to figure this out and seem to be getting nowhere.

Thanks!!

Was it helpful?

Solution

When Silverlight requests a .XAP file cross-domain, the content type must be: application/x-silverlight-app. Also, you need a cross-domain policy file on the other domain. gl

OTHER TIPS

To assist others who have this same issue, and don't want to use IFrames, please see this link, as it has solved my problem. Even though the author is referring to Silverlight 2, it has solved my problem in Silverlight 3. In case the link goes down, there are 2 things I needed to do:

-- In the Silverlight app, edit the 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 are using HtmlPage in your Silverlight app (such as when reading the QueryString passed to the hosting page), you must also add:

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

to the silverlight object in the hosting page.

Please note there are security implications to the above, and I can't help but to think this is why Microsoft does not go out of their way to disseminate this information. However in my case I don't have scriptable silverlight elements, and since I wrote the silverlight app, I don't have a problem with the hosting page allowing the silverlight app access to it.

While researching this, I noticed that this issue and corresponding solutions gets confused with a separate problem, the problem of a silverlight xap accessing a wcf service across domain boundaries. That issue does require a clientaccesspolicy.xml file located on the root of the website hosting the wcf service.

So it is possible to have the 1st site accessing a xap file on a 2nd site, which accesses a data service on a 3rd site, for maximum flexibility and re-use.

You could create a simple html file next to the .xap that contains the silverlight object and access this from an iframe. This is how http://silverlight.live.com/ fixed this issue for example.

On you main page on subA.domain.com add an iframe that show a html page on the other 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 could look something like:

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top