/// <summary>
/// ImgHandler
/// http://blog.csdn.net/bluceyoung
/// </summary>
public class ImgHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string imgURL = context.Request.Url.AbsolutePath;
if (context.Request.UrlReferrer == null)//盗用图片
{
imgURL = context.Request.MapPath("bb.jpg");
}
context.Response.ContentType = GetContentType(imgURL);
context.Response.WriteFile(imgURL);
}
private string GetContentType(string url)
{
switch (Path.GetExtension(url))
{
case ".gif":
return "Image/gif";
case ".jpg":
return "Image/jpeg";
case ".png":
return "Image/png";
default:
break;
}
return null;
}
public bool IsReusable
{
get { return false; }
}
}