本帖最后由 u011335204 于 2013-08-03 10:56:27 编辑

解决方案 »

  1.   

    <httpHandlers>
          <add verb="*" path="*.jpg" type="Protect,Haiyang"/>
        </httpHandlers>
    type里要怎么写呢?
    我的网站没定义什么空间啊
      

  2.   

    其实问题很简单就是type里怎么写,描述的有些复杂
      

  3.   

    type搞明白了context.Response.ContentType = "image/jpg";类里面上面的代码是做什么的?比如说我再想加个防pnd文件的到立案处理怎么写?
      

  4.   

    type的最后一个字符串值是程序集文件名,看这个:http://msdn.microsoft.com/en-us/library/aa903367(v=vs.71).aspx
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;/// <summary>
    ///Protect 的摘要说明
    /// </summary>
    public class Protect:IHttpHandler
    {
    public Protect()
    {
    //
    //TODO: 在此处添加构造函数逻辑
    //
    }
        public bool IsReusable
        {
            get { return true; }
        }
        public void ProcessRequest(HttpContext context)
        {
            if (null != context.Request.UrlReferrer)
            {
                context.Response.Expires = 0;
                context.Response.Clear();
                context.Response.ContentType = "images/jpg";
                context.Response.WriteFile(context.Request.PhysicalPath);
                context.Response.End();
            }
            else
            {
                context.Response.Expires = 0;
                context.Response.Clear();
                context.Response.ContentType = "text/html";
                context.Response.Write("混蛋!你在非法盗链");
                context.Response.End();
            }
        } 
    }
    我想拦截png图片发现没用
      

  6.   

    你得在IIS中添加对.png文件类型的映射才行,将其映射到asp.net处理程序,参考.aspx后缀的设置