ASP.NET关于防止盗链代码,求指点 本帖最后由 u011335204 于 2013-08-03 10:56:27 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <httpHandlers> <add verb="*" path="*.jpg" type="Protect,Haiyang"/> </httpHandlers>type里要怎么写呢?我的网站没定义什么空间啊 其实问题很简单就是type里怎么写,描述的有些复杂 type搞明白了context.Response.ContentType = "image/jpg";类里面上面的代码是做什么的?比如说我再想加个防pnd文件的到立案处理怎么写? 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图片发现没用 你得在IIS中添加对.png文件类型的映射才行,将其映射到asp.net处理程序,参考.aspx后缀的设置 手机短号分配,求思路 asp.net关于数据POST的问题 ajax客户端无刷新的省市区联动 DataList如何实现单选 请教 关于TREEVIEW显示没有层次的问题 触发器的问题 怎么分不了页 怎么在asp.net中修改IE状态栏的文字? 请问一下,我下载的.ISO文件怎么用啊?是不是要解压什么的!!!! 表格拉伸 网站发布以后,登陆网站需用户名和密码
<add verb="*" path="*.jpg" type="Protect,Haiyang"/>
</httpHandlers>
type里要怎么写呢?
我的网站没定义什么空间啊
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图片发现没用