Reputation: 924
I have existing code that passes information for a video file in php to the video player through .htaccess. I'm trying to understand how something like this can be replicated in IIS and .NET
php script:
$hash = $_GET['h'];
$streamname = $_GET['v'];
$timestamp = $_GET['t'];
$current = time();
$token = 'sn983pjcnhupclavsnda';
$checkhash = md5($token . '/' . $streamname . $timestamp);
if (($current - $timestamp) <= 2 && ($checkhash == $hash)) {
$fsize = filesize($streamname);
header('Content-Disposition: attachment; filename="' . $streamname . '"');
if (strrchr($streamname, '.') == '.mp4') {
header('Content-Type: video/mp4');
} else {
header('Content-Type: video/x-flv');
}
header('Content-Length: ' . $fsize);
session_cache_limiter('nocache');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
$file = fopen($streamname, 'rb');
print(fread($file, $fsize));
fclose($file);
exit;
} else {
header("location:.$player_id");
}
.htaccess
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)$ videoSecure.php?h=$1&t=$2&v=$3
RewriteRule ^$ - [F]
RewriteRule ^[^/]+\.(flv|mp4)$ - [F]
What this does is obfuscate and secure a video file from being downloaded directly off the sever, but still allowing it to be streamed.
I'm trying to understand if I can achieve something like this in IIS6/7 + .NET MVC4
Alternatively, would I be able to keep the php and have it execute through IIS despite a .NET environment for the majority of the site and would that produce any problems?
Upvotes: 0
Views: 69
Reputation: 14216
You can use some thing like this.
Response.AppendHeader("Content-Type", "video/mp4");
Upvotes: 1