Search code examples
silverlightbase64embedded-resource

Delivering Silverlight in HTML object or embed tag base64 encoded data


It is possible to base64 encode an image and deliver it as part of the html content using the <img src="data:image/gif;base64,UEsDBBQAAAgIALp9...MTs9Snj3==">

I notice that Silverlight's object tag is supposed to be something like:

<object type="application/x-silverlight"  
    data="data:application/x-silverlight;base64,"   
    width="300" height="300">  
    <param name="source" value="myApp.xap"/>  
<object>

and it seems that I should be able to just put in this, using the same technique as with the images:

<object type="application/x-silverlight"  
    data="data:application/x-silverlight;base64,SOFIjoije3r8...WMDioaAAA=="   
    width="300" height="300">   
<object>

And have it load the xap file data from the base64 encoding in the data parameter. But this doesn't work - it loads the Silverlight plugin and there are no errors in IE or Firefox, yet the xap module isn't run.

I know browsers can be very picky about syntax for this kind of thing, so I'm asking y'all.

The purpose is to embed Silverlight in a asp.net Server Control without the additional complexity for the developer of having to host the xap somewhere and to resolve the uri of the xap, etc. I'm primarily interested in loading the xap from the embedded base64 encoded string, but if that cannot be done, good solutions for simplifying the use of the Silverlight app to a single-line of code will have to do.

Thanks!


Solution

  • I appreciate the time you all took to look at my question. I found the "better solution" to be the WebResource.axd - it provides us the ability to load resources directly from a properly decorated assembly merely by its being present. This is perfect. I figured that I'd have to require consumers to add all kinds of garbage to the web.config for custom httpHandlers or something, but it turns out that WebResource.axd is included as of asp.net 2.0 for this purpose.

    Here's the article I found explaining it all:

    https://web.archive.org/web/20211020131200/https://www.4guysfromrolla.com/articles/080906-1.aspx