Click here to Skip to main content
15,867,704 members
Articles / General Programming / File
Article

Exposing Flash Content using HttpHandler

Rate me:
Please Sign up or sign in to vote.
4.11/5 (2 votes)
11 Oct 2013CPOL2 min read 5.1K   1  
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

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

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

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

755 members

Comments and Discussions

 
-- There are no messages in this forum --