- Open up IIS Manager. In the site properties, click the "Home directory" tab then click the "Configuration" button.
-
Add an entry for .flv. The Executable path is whatever the aspnet_isapi.dll path is for your version of .NET Framework. Check some of the other file types like .config to be sure. Set Verbs to "Limit to:" with the value GET,HEAD,POST,DEBUG. Click OK get back to the site properties.
-
If you have not done so already, you'll need to make sure you have a mime type for flv files, so go to the HTTP Headers tab and click the MIME Types... button. If .flv does not appear, click new. Extention is .flv and MIME type is flv-application/octet-stream. You may have something else here and I'm not sure if it matters if you have this exact value but this works for me. Click OK and get back to the site properties.
-
One thing to consider is the size of the flv files and how long they will take for your visitors to download. In my case, I have some flv files that are 150MB, so it can take some slow DSL users maybe 30 min or more to download as they watch. Because of this, the script would time out before the download is done, cutting the video off. By default the script will stop in 110 seconds, so if that is not enough time for some slower connections, go to the ASP.NET tab and click Edit Configuration. Now go to the application tab and change the Request execution timeout to a higher value. I chose 1800 seconds. We are done with the site properties for now.
-
In order to make sure any request for a .flv file is handled by ASP.NET, edit the web.config file (should be in the root of your website) and add the following lines just before </system.web> near the end of the file:
<httpHandlers>
verb="*" path="*.flv" type="FLVStreaming" />
</httpHandlers>
using System;
using System.IO;
using System.Web;
public class FLVStreaming : IHttpHandler
{
private static readonly byte[] _flvheader = HexToByte("464C5601010000000900000009");
public FLVStreaming()
{
}
public void ProcessRequest(HttpContext context)
{
try
{
int pos;
int length;
// Check start parameter if present
string filename = Path.GetFileName(context.Request.FilePath);
using (FileStream fs = new FileStream(context.Server.MapPath(filename), FileMode.Open, FileAccess.Read, FileShare.Read))
{
string qs = context.Request.Params["start"];
if (string.IsNullOrEmpty(qs))
{
pos = 0;
length = Convert.ToInt32(fs.Length);
}
else
{
pos = Convert.ToInt32(qs);
length = Convert.ToInt32(fs.Length - pos) + _flvheader.Length;
}
// Add HTTP header stuff: cache, content type and length
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(DateTime.Now);
context.Response.AppendHeader("Content-Type", "video/x-flv");
context.Response.AppendHeader("Content-Length", length.ToString());
// Append FLV header when sending partial file
if (pos > 0)
{
context.Response.OutputStream.Write(_flvheader, 0, _flvheader.Length);
fs.Position = pos;
}
// Read buffer and write stream to the response stream
const int buffersize = 16384;
byte[] buffer = new byte[buffersize];
int count = fs.Read(buffer, 0, buffersize);
while (count > 0)
{
if (context.Response.IsClientConnected)
{
context.Response.OutputStream.Write(buffer, 0, count);
//Starts sending to client right away
context.Response.Flush();
count = fs.Read(buffer, 0, buffersize);
}
else
{
count = -1;
}a
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
public bool IsReusable
{
get { return true; }
}
private static byte[] HexToByte(string hexString)
{
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
}
This is mostly off the top of my head and I set this up a year ago so I'm sorry if I missed something.