Our application was one that presented real time data and charts to the user based on some criteria selected by the user. The chart and model were displayed to the user in a Flash component (.swf files) created using Adobe Flex.
Things were running pretty good since were the developers of the Flash (.swf) component. Adding the flash component in the aspx file was easy using the object tag
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="200"> <param name="movie" value="StylingComp.swf" /> <param name="quality" value="high" /> <param name="wmode" value="opaque" /> <param name="swfversion" value="7.0.70.0" />
</object>
Things changed when some of the other applications in the organization wanted to use our custom made flash component to be displayed in their application. Sharing the .swf file made no sense as every time we made any change to the component we had to share the latest .swf files to the with all the other application.
Doing some research we decided to create our custom handler for showing content in .swf format.
Creating a Custom handler is pretty simple.
1. Right click on the web project/web site
2. Click Add New Item
3. Select Generic Handler
Below is the code that read the .swf file and writes it to Response stream.
The point to keep in mind here is changing the content type to "video/x-flv"
using System;
using System.Data;using System.Web;using System.Collections;using System.Web.Services;using System.Web.Services.Protocols; namespace TestWebApplication{ /// <summary> /// Summary description for $codebehindclassname$ /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class FlashHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "video/x-flv"; byte[] content=null; using (System.IO.FileStream fso = new System.IO.FileStream(context.Server.MapPath("StylingComp.swf"), System.IO.FileMode.Open)) { content = new byte[fso.Length]; fso.Read(content,0, Convert.ToInt32(fso.Length)); } context.Response.BinaryWrite(content); context.Response.Flush(); context.Response.Close(); } public bool IsReusable { get { return false; } } }
}
This is just a starting point you can modify the ProcessRequest methods
· To check if the user has subscribed for the content
· Send the user, content based on the Request collection context.Request[..].
The context and used to perform all the task that are possible in asp.net
Next to use these content in you aspx page you will have to do just a minor change to you object tag.
Consider the name of the application as “DemoFlashHandler” which is hosted on you local IIS ,we will have to change the value of the object tag to “http://localHost/DemoFlashHandler/FlashHandler.ashx”
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="200"> <param name="movie" value="FlashHandler.ashx" /> <param name="quality" value="high" /> <param name="wmode" value="opaque" /> <param name="swfversion" value="7.0.70.0" />
</object>
Now any application can access you .swf component using this simple url