ASP.NET关于防止盗链代码,求指点

The Big Short 2013-08-03 10:54:41
以下是一段模仿在网上看到的防盗链的代码

原文地址:http://www.jb51.net/article/26174.htm

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 = "image/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();
}
}
}

我的Web.config
<httpHandlers>
<add verb="*" path="*.jpg" type="Protect,Haiyang"/>
</httpHandlers>

运行时报错,说是web.config有问题
在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。

分析器错误消息: 未能加载文件或程序集“Haiyang”或它的某一个依赖项。系统找不到指定的文件。

但我不知道要怎么改?什么空间什么的也不知道是什么


这是文件路径
...全文
151 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
webdiyer 2013-08-05
  • 打赏
  • 举报
回复
引用 5 楼 u011335204 的回复:
我想拦截png图片发现没用
你得在IIS中添加对.png文件类型的映射才行,将其映射到asp.net处理程序,参考.aspx后缀的设置
The Big Short 2013-08-05
  • 打赏
  • 举报
回复
引用 4 楼 webdiyer 的回复:
type的最后一个字符串值是程序集文件名,看这个:http://msdn.microsoft.com/en-us/library/aa903367(v=vs.71).aspx
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图片发现没用
webdiyer 2013-08-04
  • 打赏
  • 举报
回复
type的最后一个字符串值是程序集文件名,看这个:http://msdn.microsoft.com/en-us/library/aa903367(v=vs.71).aspx
The Big Short 2013-08-03
  • 打赏
  • 举报
回复
type搞明白了 context.Response.ContentType = "image/jpg"; 类里面上面的代码是做什么的?比如说我再想加个防pnd文件的到立案处理怎么写?
The Big Short 2013-08-03
  • 打赏
  • 举报
回复
其实问题很简单就是type里怎么写,描述的有些复杂
The Big Short 2013-08-03
  • 打赏
  • 举报
回复
<httpHandlers>
      <add verb="*" path="*.jpg" type="Protect,Haiyang"/>
    </httpHandlers>
type里要怎么写呢? 我的网站没定义什么空间啊

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧