namespace MyHandler
{
public class Jpg : IHttpHandler
{
public bool IsReusable
{
get
{
return true;
}
}
public void ProcessRequest(HttpContext context)
{
//判断是否是本地引用,如果是则返回给客户端正确的文件
if (context.Request.UrlReferrer == null)
{
return;
}
if (context.Request.UrlReferrer.Host == "localhost")
{
context.Response.Expires = 0;//设置客户端缓冲中文件过期时间为0,即立即过期。
context.Response.Clear();//清空服务器端为此会话开辟的输出缓存
//context.Response.ContentType = "image/jpeg";
context.Response.WriteFile(context.Request.PhysicalPath);//将请求文件写入到服务器端为此会话开辟的输出缓存中
context.Response.End();//将服务器端为此会话开辟的输出缓存中的信息传送到客户端
}
else
{
//非法连接 可显示广告
//context.Response.WriteFile("ad.jpg");
}
}
}
}
在站点的web.config配置
<httpHandlers>
<add verb="*" path="*.jpg" type="MyHandler.Jpg,MyHandler"/>
</httpHandlers>
在IIS映射.flv的对应执行程序路径为:C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/aspnet_isapi.dll