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

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

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.

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

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>

Related

Unable to load Silverlight in angular2 when embedded in a component

Current behavior
When embedding and loading Silverlight.xap directly inside an HTML page, it works fine. But when we move same code inside a component, it won't load the Silverlight. DOM in both cases, i.e. embedding and loading through HTML and through component, doesn't show any difference.
Code of Silverlight-app.Component.HTML Page
When we load this page directly, i.e. localhost/OurApp/Silverlight-app.Component.HTML, silverlight content gets loaded and it works fine. But when we open index.html in browser (which is main component of our angular2 and Silverlight-app.Component.HTML page is child component of index.html), it don't load silverlight content.
<section>
<div>
<object id="silverlightControlHost" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%" style="min-height: 100%; height: 1000px">
<param name="source" value="clientbin/SilverlightApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="5.0.61118.0" />
<param name="autoUpgrade" value="true" />
<param name="Windowless" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration: none">
<img src="images/slmedallion.png" alt="Get Microsoft Silverlight" style="border-style: none" />
</a>
</object>
<iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px;
border: 0px"></iframe>
<iframe id="desktop" style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe>
</div>
</section>
Expected/desired behavior
Embedding and loading Silverlight component should have same behavior irrespective of loading through HTML or through component.
What is the motivation / use case for changing the behavior?
We are migrating our Silverlight application to Angular2. As complete migration will take months, we are keeping some of the silverlight modules as well.
Images for better understanding of the issue
this example does exactly what you need :)
https://github.com/lohiarahul/Angular2-Silverlight-Starter

Silverlight div leaves remnant of prior screen before load

I have one page with a Silverlight object on it, and many times when visiting the page, there is between .1-2 seconds where the previous screen's content is frozen inside the box where the Silverlight object should be, before Silverlight starts loading with the 1-99% progress circle. I'm using Chrome. It is very sloppy looking loading. I image the problem might go unnoticed after the first cache, but is there any way to avoid this visual remnant?
<div id="silverlightControlHost" style="height:440px; padding-top:15px" >
<object name="slupload" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="440px" height="100%" >
<param name="source" value="../ClientBin/SilverlightWebcam.xap?#nocache"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.41108.0" />
<param name="autoUpgrade" value="true" />
<param name="onLoad" value="pluginLoaded" />
<param name="initParams" value="userid=#ViewBag.UserID" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.41108.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
Try changing the visibility of the Silverlight object with Javascript so that it appears after the page has loaded/rendered.

Source property of Silverlight object

<div id="silverlightControlHost" >
<object id="idThObject" data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/MySolution.xap"/>
<!--<param name="source" value="http://www.mysite.com/ClientBin/MySolution.xap"/> **NOT WORK**-->
...
</div>
Hi to ALL !
My Silverlight object exist on sever side in folder and when I try to load it like this : <param name="source" value="http://www.mysite.com/ClientBin/WebSolution.xap" />
This is doesn't work, but it I load this locally :
<param name="source" value="ClientBin/MySolution.xap"/>, it's work fine.
So what can I do to load my *.xap file from server or I don't have any chance to do it ?
Please check that you have added the required mimetypes for silverlight in IIS on the server.
map the following.
.xap application/x-silverlight-app
.xaml application/xaml+xml
.xbap application/x-ms-xbap
I didn't change any values of any type in html code. Visual Studio 2010 create standard template :
<div id="silverlightControlHost" style="font-size: small;color: red;">
<object id="idThObject" data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/WebSolution.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true"
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object><iframe id='_sl_historyFrame' style='visibility:hidden;height:0;width:0;border:0px'></iframe></div>
Only one point : provider of my site yahoo.com. So by default this guys don't use IIS.
So you think this is problem ? That Apache doesn't know this :
< ...data="data:application/x-silverlight," type="application/x-silverlight-2"/>
look like I have to move to another provider, which support IIS.

Users PC installing wrong version of Silverlight

I have a Silverlight Application (SL4) which I have rolled out to people within my network. The problem I have is that when some of my users go to access the SL application it is asking them to download a Silverlight 3 plug in.
Is there something I need to set in my Project to ensure that the Plug in installs SL4.
Sounds like the host page HTML is incorrectly set. Your object tag HTML ought to look like this:-
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightApplication1.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.60310.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
</div>
Note in particular the minRuntimeVersion param and the "&v=4.0.60310.0" query string value of the href in the object fallback content.

How to customize or remove the SilverLight Update alert box?

We recently added a small silverlight client that loads on every page load.
However for the visitors who for some reason don`t want to upgrade their silverlight version they are seeing this annoying message on every single page load:
From where is this alert triggered and how can I stop it from being triggered? Ive looked in the silverlight.js file but cant find it.
Following is the code where the Silverlight app is embeded:
<div id="silverlightControlHost">
<script type="text/javascript" src="http://$CommonHelps.GetSiteInfoByDomain().ContentDomainJavascript/Silverlight.js"></script>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="5" height="5" >
<param name="source" value="/ClientBin/AppLaunch.Bloc.Frontend.SilverLight.UserOnlineClient.xap"/>
<param name="onError" value="AppLaunch.Chatbar.onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" target="_blank">
Install silverlight to chat with your friends
</a>
</object>
<iframe id="_sl_historyFrame"></iframe>
</div>
<p id="UserOnlineClientConnectionClientEx"></p>
Tim Heuer blogged the answer to this a while ago in his silverlight 3 beta install guidance blog post. You need to make sure you have minRuntimeVersion with a minimum version, autoUpgrade param set to false, and onerror param set to a javascript function, such as below:
<param name="minRuntimeVersion" value="3.0.40307.0" /><param name="autoUpgrade" value="false" /><param name="onerror" value="pluginError" />
You then need the js error function, called pluginError above to check for errorCode 8001. Set what you want the user to see within that if statement. This stops the popup!

Resources