asp.net 实现防迅雷等下载工具盗链

来源:爱站网时间:2017-11-22编辑:网友分享
利用IHttpHandler接口来监听对本网站的资源请求后缀名是否是我们要阻止的文件,如果是再判断是否有下载权限。没有就给它返回一个默认的无用的文件。
主要代码如下:

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/octet-stream";
HttpRequest req = context.Request;
string filename = req.Url.AbsolutePath;
string userid = string.Empty;
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies["userid"] != null)
{
userid = HttpContext.Current.Request.Cookies["userid"].Value;
}
if (userid == "1")
{
string uuu = context.Server.MapPath(filename);
context.Response.TransmitFile(uuu);
}
else
{
string u2 = context.Server.MapPath("default.rar");
context.Response.WriteFile(u2);
}
}

设计思想如下:
1. 利用IHttpHandler接口来监听对本网站的资源请求后缀名是否是我们要阻止的文件,如果是再判断是否有下载权限。没有就给它返回一个默认的无用的文件。

上一篇:.net发送邮件实现代码

下一篇:C# 邮件地址是否合法的验证

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载