namespace WebHotlinkProtection
{
public class HotlinkProtectionHandler:IHttpHandler
{
public bool IsReusable
{
get {
throw new NotImplementedException(); }
}
public void ProcessRequest(HttpContext context)
{
//监听是否本站发起的请求
if (!context.Request.UrlReferrer.Host.StartsWith(
"localhost"))
{
context.Response.Expires =
0;
context.Response.Clear();
context.Response.ContentType =
"image/jpg";
//输出防盗链图片
context.Response.WriteFile(context.Request.Physical
ApplicationPath +
"\\no.jpg");
context.Response.End();
}
else {
context.Response.Expires =
0;
context.Response.Clear();
context.Response.ContentType =
"image/jpg";
context.Response.WriteFile(context.Request.PhysicalPath);
context.Response.End();
}
}
}
}