惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 司徒正美
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
Help Net Security
Help Net Security
N
News and Events Feed by Topic
O
OpenAI News
L
LangChain Blog
F
Full Disclosure
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
Cloudbric
Cloudbric
W
WeLiveSecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
罗磊的独立博客
Attack and Defense Labs
Attack and Defense Labs
PCI Perspectives
PCI Perspectives
TaoSecurity Blog
TaoSecurity Blog
AI
AI
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
T
Threatpost
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Last Week in AI
Last Week in AI
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 聂微东
P
Proofpoint News Feed
Latest news
Latest news
S
SegmentFault 最新的问题
J
Java Code Geeks
T
Threat Research - Cisco Blogs
H
Help Net Security
P
Privacy International News Feed

博客园 - Juniy

DedeCms 模板学习1 DIV盒子的CSS平面图 在asp.net页面中传递中文参数 - Juniy - 博客园 sqldatasource连接excel 2003 - Juniy - 博客园 SSI与SHTML学习 AjaxPro(ajax架构)在ASP.NET中的使用 常用命令备忘 ASP.NET"正在中止线程"错误原因 将用户重定向到另一页的几种方法 贝塞尔样条 PetShop4 下载地址 ASCII 非打印控制字符表 (摘抄)什么是反射机制 (摘抄)禁止搜索引擎收录的方法(robots.txt文件的使用) (摘抄)DIV布局和网页设计 ASP.NET(C#)文件读写函数 C#中using的使用 修改url前图标(网上查到) JavaScript小技巧一
.NET 实现ISAPI过滤器,指定类型文件防下载
Juniy · 2007-01-30 · via 博客园 - Juniy

using System;
using System.Web;
using System.Configuration;
namespace CheckDownload
{
#region Corp
// By : 公子哥
// .NET 实现ISAPI过滤器,文件防下载
#endregion
public class DownloadHandler:IHttpHandler,System.Web.SessionState.IRequiresSessionState
{
#region IHttpHandler 成员
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
HttpRequest req = context.Request;
//从Request对象中获取所请求文件的物理路径
string strNew = "";
string strtmp = req.PhysicalPath;
unsafe
{
fixed(char *pValue = strtmp)
{
char * pnew= pValue;
pnew=pnew+strtmp.LastIndexOf(".");
for (;*pnew !='\0';++pnew)
{
strNew+= Convert.ToString(*pnew);
}
}
}
//根据Session中UserName是否存在判断用户是否登陆
if (context.Session["UserName"] == null)
{
//未登陆
System.Web.HttpContext.Current.Server.Transfer(ConfigurationSettings.AppSettings["LoginShow"].ToString());
}
else
{
//防.bokee文件,如果有多个文件应加入多个文件判断
if (strNew.ToLower().Equals(ConfigurationSettings.AppSettings["FileTypes"].ToString().ToLower()))
{
System.Web.HttpContext.Current.Server.Transfer(ConfigurationSettings.AppSettings["Error"].ToString());
}
}
}
#endregion
}
}

以上代码编译CSC,例:
(脚本),相关路径应以您的实际环境而定
set MyPath=C:\Inetpub\wwwroot\isapitest
cd %MyPath%
csc /t:library /out:./bin/download.dll Class1.cs /unsafe
pause

接下来设置IIS对扩展名.bokee的映射,将.bokee的解析权交给aspnet_isapi.dll
动作选择为:全部

最后配置 web.config文件

<appSettings>
<add key="FileTypes" value=".bokee" /><!-- 要过滤的文件扩展名 -->
<add key="Error" value="./messageshow.html" /> <!-- 如果用户登陆但没有权限 -->
<add key="LoginShow" value="./loginshow.html" /> <!--用户未登陆时候的提示 -->

</appSettings>

<httpHandlers>
<add verb="*" path="*.bokee" type="CheckDownload.DownloadHandler, download" />
</httpHandlers>