Posted on 6/8/2007 4:46:15 PM
in #.NET
Here is a simple example of how to create a web proxy for a flash file.
Flash has many restrictions for files loaded from a different domain. When you don't have any control over the flash file located on a remote server, a solution might be the creation of a web proxy like the following one:
<%@ Page language="c#" AutoEventWireup="false" Inherits="PhotoSite.util.PreviewPageBase" %>
<%@ Import namespace="System.Net"%>
<%@ Import namespace="System.IO"%>
<script language="C#" runat="server">
override protected void OnInit(EventArgs e)
{
string sURL = Request["path"];
if(sURL == null) return;
WebRequest request;
request = WebRequest.Create(sURL);
WebProxy myProxy = new WebProxy("proxy",80);
myProxy.BypassProxyOnLocal = true;
request.Proxy = WebProxy.GetDefaultProxy();
this.Response.ContentType = "application/x-shockwave-flash";
this.Response.AddHeader("Content-Type", "application/x-shockwave-flash");
// set the content disposition
this.Response.AddHeader("Content-Disposition", "inline;filename=digitalAlbum_v1_7_2.swf");
using(Stream stream = request.GetResponse().GetResponseStream())
{
this.Response.BinaryWrite(StreamToByteArray(stream));
}
}
public static byte[] StreamToByteArray (Stream stream)
{
byte[] buffer = new byte[32768];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = stream.Read (buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write (buffer, 0, read);
}
}
}
</script>
Share this post:
digg
Stumble Upon
del.icio.us
E-mail
|