views:

337

answers:

2

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!

+2  A: 

Even if you were to get it to work, I recommend against that approroach for the following reasons:

  1. The time that it takes to load the entire page would be long
  2. This doesn't take advantage of any browser caching of the XAP so that every time the page loads, the xap must be read.
Michael S. Scherotter
Thanks Michael. +1
uosɐſ
A: 

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:

http://www.4guysfromrolla.com/articles/080906-1.aspx

uosɐſ