Some mvc pages doesn't see silverlight in thinktecture server - silverlight

I have a very strange problem.
I would like to add some silverlight page to an action method in the Account controller (view for action method within it) , however when I navigate it gives me silverlight exception that it cannot download the silverlight.
But when I move it another controller (say Home controller view) it works well !!
I have checked existence of xap , MIME types in ISS everything is well

For some unknow reason I had to write
<param name="source" value="<% = Url.Content("~/ClientBin/TakingMyPicture.xap") %>"/>
rather than
<param name="source" value="~/ClientBin/TakingMyPicture.xap"/>

Related

Can I host my Silverlight XAP file from a Azure Blob or CDN?

Having clients over the globe, we encountered some serious loading delays for initially retrieving the XAP from various locations. The hope was that we could host the compiled XAP in the cloud, offering a closer download depending on the end-user's location.
We are using RIA services, but the service endpoints need to remain on our local server, because of data connections, connections to internal services, etc.
How do we distribute the XAP using cloud-based services, while having it continue to function the same as it does currently?
EDIT: Since I worked through this and found the answer myself, I've moved the steps that I had accomplished before out of my question and into the answer to better facilitate a good Q&A format and for anyone else approaching the problem from step zero.
After hammering away at this, I found the solution to get it almost completely working.
Update RIA service endpoints with absolute URIs to refer back to the hosting page rather than relative to the XAP location itself.
Ensure all image (etc.) content is loaded from either resources in the XAP or else ensure they are uploaded as well to the Azure Storage Blob. Any relative paths will try to resolve to the XAP location.
Generate the XAP file and upload to the Azure Storage Blob. You will need to ensure that the XAP has Content-Type of application/x-silverlight-app. I accomplished this using Azure Storage Explorer. You can set Content-Type by opening the properties of the item via double-click, but, and even better, you can click the Settings gear to 'Edit Content Types' and add a rule that .xap is application/x-silverlight-app so that it will be automatically set any time you upload.
Ensure you have a proper cross domain policy in place.
Update your hosting page to supply the new source. Additionally, you will need to add the enablehtmlaccess param if not already set, since this value is false by default for cross domain.
For item #1, I accomplished using code such as the following:
var u = HtmlPage.Document.DocumentUri;
Site = u.AbsoluteUri.Substring(0, u.AbsoluteUri.LastIndexOf('/'));
MyServiceUri = new Uri(Site + "/ClientBin/My-Namespace-MyService.svc", UriKind.Absolute);
For item #4, my code looked like:
<param name="source" value="<%= Request.Url.Scheme %>://mytest.blob.core.windows.net/my-container/MySilverlightApp.xap"/>
<param name="enablehtmlaccess" value="true" />
One last thing to note: If using a custom splash screen, then figure out how to get this to work. I don't know how. What I have found out is that if you set splashscreensource as the location of a .xaml file, then it simply does not load. It will just show the basic silverlight load percent screen, which does at least seem to report load % correctly. In order to get the custom splash screen to load, it seems to only work when included inline. You can do this via:
<script id="xamlSplash" type="text/xaml">
<%= System.IO.File.ReadAllText(Context.Server.MapPath("~/Loading.xaml")) %>
</script>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="splashscreensource" value="#xamlSplash" />
However, while this will show the custom splash screen, it will not work if you have any progress report on the splash screen. The javascript function referenced by onsourcedownloadprogresschanged will never fire. I could not find why this was the case, nor a way around it. You'll just have to have a spinning animation or the like in place of an actual % progress indicator.

?How do we stop IE9 from always retrieving Out-of-Date Data from Cache?

Our project uses Silverlight 4 and Microsoft Pivot Viewer which is a Data Presentation tool that works in Silverlight.
Microsoft Pivot Viewer makes it easier to interact with massive amounts of data in ways that are powerful, informative, and fun. Microsoft Live Labs tried to step back and design an interaction model that accommodates the complexity and scale of information rather than the traditional structure of the Web.
The Module within our application that uses Siliverlight and Microsoft Pivot Viewer has quite a bit of caching problems.
The Module within our application that uses Siliverlight and Microsoft Pivot Viewer dynamically retrieves images at runtime so that it present the images to the user in Siliverlight and Microsoft Pivot Viewer.
The problem that we have is that IE9 caches the images in Siliverlight and Microsoft Pivot Viewer.
The HTTP Response Headers on IIS is configured in such a way that Web Content expires immediately.
As soon as you add any URL parameter (e.g. “?v1″ or a dynamically generated parameter like in your code), client-side
caching is turned off by the browser unless an expiration date is explicitly set.
We tried the following in the Siliverlight and Microsoft Pivot Viewer Host ASPX file:
<div id="silverlightControlHost">
<object id="pivotViewer" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="900">
<%
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
string orgSourceValue = #"ClientBin/SilverlightPivotViewer.xap";
string param;
if (System.Diagnostics.Debugger.IsAttached)
param = "<param name=\"source\" value=\"" + orgSourceValue + "\" />";
else
{
string xappath = HttpContext.Current.Server.MapPath(#"") + #"\" + orgSourceValue;
DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
param = "<param name=\"source\" value=\"" + orgSourceValue + "?ignore="
+ xapCreationDate.ToString() + "\" />";
}
Response.Write(param);
%>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="cxml=Resources.cxml" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.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>
Google Chrome and Mozilla Firefox seem to work fine.
However, IE9 fails because it keeps getting Out-of-Date data from Cache for Silverlight.
Our following efforts failed to resolved the caching issue:
1) IE9 of user still caches even after The HTTP Response Headers on IIS is configured in such a way that Web Content expires immediately.
2) IE9 of user still caches even after we ensure that the Silverlight XAP url is appended with a dynamically generated parameter.
Could someone please provide some steps as to how we should resolve the issue?
A very temporary fix - which you can only use during development - is to F12 on the webpage to bring up the developer tools. Then from the menu you pick Cache > Always refresh from server.
I wish I knew how to fix this more permanently.

Unable to register silverlight user control in aspx page

I have made a simple silverlight application. Everything is working fine but I am unable to use silverlight user control as my aspx page shows only embedded object code.
I have also tried to register the silverlight control with the following code:
<%# Register Assembly="System.Web.SilverLight" Namespace="System.Web.UI.SilverLightControls" TagPrefix="asp" %>
but it did not work. I want to do this, so that I would able to pass parameter to silverlight control from my aspx page.
How should I register the silverlight user control in my aspx page? I am using silverlight 3.0 version.
The Silverlight server control is no longer supported in version 3.0. You will need to use the object html tag instead. See my answer to a similar question here.

Hosting Silverlight widget from local file system

I'm trying to host a remote Silverlight widget in an html file that will exist locally on the hard drive, but whenever I open the html file, the Silverlight content does not show up. If I move the file to a web server and then access it through http, it works perfectly. I figured out (or at least I assume) that the widget is trying to make a call back to the web server but it's failing because of the cross zone restrictions in SL 2+. I've also seen a few reports from users talking about running into this issue when debugging from a local file. My question is, how can I tell for sure that this is the issue going on/what tools might I use to verify my hypothesis?
Additionally, (knowing full well that there are elevation of privileges security concerns to take into account) is there any way that I could declare the web services the widget calls as safe (for instance adding to the trusted sites) in such a way that Silverlight would be able to perform the calls without the security exceptions?
An example of a widget I'm talking about is below:
<object
type="application/x-silverlight-2"
data="data:application/x-silverlight-2,"
width="400" height="400">
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="background" value="#141414" />
<param name="splashScreenSource"
value="http://memorabilia.hardrock.com/Widget/3.2009.1014.0/Splash.xaml" />
<param name="source"
value="http://memorabilia.hardrock.com/Widget/3.2009.1014.0/HardRock.Memorabilia.Silverlight.Widget.xap" />
<param name="enableHtmlAccess" value="true" />
<param name="initParams" value="item=034739" />
<a href="http://go.microsoft.com/fwlink/?linkid=149156&v=3.0.40624.0">
<img src="http://memorabilia.hardrock.com/Widget/3.2009.1014.0/Ping.gif?type=install&item=034739"
style="background:#141414
url(http://content.memorabilia.hardrock.com/Assets/Images/widget/034739.jpg)
no-repeat center;margin:0;padding:0;border:0;"
width="400" height="400" />
</a>
</object>
This is an issue of a cross protocol violation - a page with a file:// protocol cannot access assets with an http:// protocol. This also helps protect your your computer from accessed by a malicious Silverlight application.

How to embed Silverlight control in blog page?

How can I embed a demonstration applet written in Silverlight within a blog post? Is it possible to do so using any hosted blog engines, or only using a blog engine that I host myself?
I assume that I will need to use the same tags and .js as in a regular (X)HTML page with a SL control. Are there any hosted blog engines that will permit me to enter this? (Is it possible with blogger?)
Does the SL security model mean that the XAP file need to be hosted on the same site as the blog pages itself?
You can host a Silverlight app in HTML using the <object> tag, there is no need for the blog host to understand any of this. There is no server side element to hosting a Silverlight app its a purely client side thing.
<object id="SL" data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="width:400px; height:300px">
<param name="source" value="MySLApp.xap" />
<param name="minRuntimeVersion" value="3.0.40624.0 />
<param name="initParams" value="someParam=value" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" style="border-style: none" alt="Get Microsoft Silverlight" />
</a>
</object>
In this case the Silverlight app "MySLApp.xap" is placed in the same folder as the HTML page using it. However it could be on a different server if you like. However access to the HTML Bridge will be blocked but then if your app is self contained and does not need to communicate with the host page then there is no problem.
I created a Silverlight xap to host hero images OR video in my wordpress theme - I pass the content to it using initparams and custom fields per post.
That way I can use the same xap to host videos with media controls if appropriate or images with cool fade ins/click effects
example image post:
http://www.blackspike.com/site/html/display-google-docs-spreadsheets-in-wordpress
example video post (click vid for controls):
http://www.blackspike.com/site/wpf/hanselmans-babysmash
Both using the same xap!
An easy solution that worked for me is just to use an iFrame. So I published the regular TestPage.html generated by Visual Studio to my web site (along with the .XAP file of course) and then embedded it:
<iframe src="http://www.lostbearlabs.com/sl/Spring001/TestPage.html" frameborder="0" width="400" height="400" scrolling="no" ></iframe>
Using blogger, I discovered this gotcha: Any attempt to make the HTML pretty (e.g. by splitting it into separate lines) causes blogger to insert spurious <br> tags into the output, even if I do my edits using the "Edit HTML" view. So the iFrame tag must all be on a single line!!
You might want to check your host has the required MIME types mapped:
http://learn.iis.net/page.aspx/262/configuring-iis-for-silverlight-applications/
according to this Server 2008 IIS7 should work out of the box but IIS6 may require MIME types adding...
The solution marked as answer above works well if the HTML page and the Silverlight xap file are hosted on the same server.
As this is not possible in most of the cases, as most of the bloggers use either blogger/WordPress. We do not have any way of setting the mime type on these hosting providers.
Here is a good link which explains in detail regarding hosting an Silverlight application in blogger.

Resources