Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a Silverlight XAP file across a domain?

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!!

like image 376
Jereme Avatar asked Jun 26 '09 21:06

Jereme


People also ask

How do I read an XAP file?

XAP files can be opened and viewed in a text editor, but they should not be edited manually. Instead, project files should only be modified with XACT.

When we create a Silverlight application XAP file is created automatically?

Every time you run Silverlight application, automatically visual studio creates the XAP file and deploy to the web site. XAP file is basic deployment in Silverlight. XAP file is a ZIP file. It contains many files needed to run Silverlight application at the client browser.

How do I create an XAP file in Silverlight?

xap file look like. Open Visual Studio and create a new project by selecting "Silverlight Application" under the project type "Silverlight". Choose the project name "SilverlightTest". In the next screen, choose the option "automatically generate a test page to host Silverlight at build time".


2 Answers

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.

like image 185
Roy McDonough Avatar answered Sep 19 '22 00:09

Roy McDonough


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

like image 35
Erik Mork Avatar answered Sep 17 '22 00:09

Erik Mork