asp.net 實現(xiàn)防迅雷等下載工具盜鏈
更新時間:2009年02月21日 03:55:15 作者:
利用IHttpHandler接口來監(jiān)聽對本網(wǎng)站的資源請求后綴名是否是我們要阻止的文件,如果是再判斷是否有下載權(quán)限。沒有就給它返回一個默認的無用的文件。
主要代碼如下:
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);
}
}
設(shè)計思想如下:
1. 利用IHttpHandler接口來監(jiān)聽對本網(wǎng)站的資源請求后綴名是否是我們要阻止的文件,如果是再判斷是否有下載權(quán)限。沒有就給它返回一個默認的無用的文件。
復制代碼 代碼如下:
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);
}
}
設(shè)計思想如下:
1. 利用IHttpHandler接口來監(jiān)聽對本網(wǎng)站的資源請求后綴名是否是我們要阻止的文件,如果是再判斷是否有下載權(quán)限。沒有就給它返回一個默認的無用的文件。
相關(guān)文章
IIS應用池回收造成Application_Start中定時執(zhí)行程序停止的問題的解決方法
最近在做一個項目,需要在程序中定時不斷的執(zhí)行某些操作,結(jié)果發(fā)現(xiàn)每天7,8點過后到第二天9點,定時程序經(jīng)常都沒有在執(zhí)行,后來才知道由于IIS的應用池回收導致Application停止。2010-03-03
.NET?Core?Web?APi類庫內(nèi)嵌運行的方法
這篇文章主要介紹了.NET?Core?Web?APi類庫內(nèi)嵌運行的方法,本節(jié)我們重點討論如何內(nèi)嵌運行.NET Core Web APi類庫,同時介紹了兩種激活比如控制器特性方案,需要的朋友可以參考下2022-09-09
ASP.NET中iframe框架點擊左邊頁面鏈接 右邊顯示鏈接頁面內(nèi)容
這篇文章主要介紹了ASP.NET中iframe框架點擊左邊頁面鏈接,右邊顯示鏈接頁面內(nèi)容的實現(xiàn)代碼,感興趣的小伙伴們可以參考一下2016-07-07
關(guān)于Swagger優(yōu)化的實戰(zhàn)記錄
Swagger是一個規(guī)范和完整的框架,用于生成、描述、調(diào)用和可視化?RESTful風格的Web服務,下面這篇文章主要給大家介紹了關(guān)于Swagger優(yōu)化的相關(guān)資料,需要的朋友可以參考下2022-04-04

