using System;
using System.Web;
namespace CustomHandler{
public class JpgHandler : IHttpHandler{
public void ProcessRequest(HttpContext context){
// 获取文件服务器端物理路径
string FileName = context.Server.MapPath(context.Request.FilePath);
// 如果UrlReferrer为空,则显示一张默认的禁止盗链的图片
if (context.Request.UrlReferrer.Host == null){
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile("/error.jpg");
}else{
// 如果 UrlReferrer中不包含自己站点主机域名,则显示一张默认的禁止盗链的图片
if (context.Request.UrlReferrer.Host.IndexOf("yourdomain.com") > 0){
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile(FileName);
}else{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile("/error.jpg");
}
}
}
public bool IsReusable{
get{ return true; }
}
}
}我的是VS2005 在命令窗口输入csc /t:library /r:System.Web.dll CustomHandler.cs后提示我csc无效
还有在我重新生成项目时提示我JpgHandler : IHttpHandler,不能实现接口成员System.Web.IHttpHandler.IsReusable
求高手解释下~

解决方案 »

  1.   

    检查页面相关命名空间
    如inhrtits等
      

  2.   

    呃还是不行啊,我把CustomHandler.cs放到了APP_CODE中了~跟这个没关系吧?现在就是无法编译成DLL文件我很费解啊,为什么每次都提示我csc命令无效呢?
      

  3.   

    如果你单单cmd打开dos命令界面,当然不能调用csc程序。在开始-程序里面,找到vs的Visual Studio 2005 命令提示
      

  4.   

    我的系统是2003~
    找到vs的Visual Studio 2005 命令提示运行csc /t:library /r:System.Web.dll CustomHandler.cs
    提示我未找到CustomHandler.cs源
    为未指定输入
    还有我重新生成项目提示我JpgHandler : IHttpHandler,不能实现接口成员System.Web.IHttpHandler.IsReusable
      

  5.   

    项目中已经产生错误了,怎么能成功编译成dll文件;建议检查下代码