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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 吴建明

请讨论这个数据库该如何设计? vs2005读写vs2008项目 一个计算程序执行时间的批处理 使用fckeditor一个怪问题。。。 如何在ashx里提取context.Request.Files? 一个nhibenate的hql问题! 请问这样一个特殊的文本编辑器该如何实现? 还是关于无法加载DLL(OCI.DLL)问题解决办法! How to get Intellisense for Web.config and App.config in Visual Studio .NET?(转载) 欢迎大家讨论一个关于界面显示的问题!! 用installshield打包的asp.net程序 欢迎参与讨论一个分布式数据同步的问题! WF的tips 请问一下:诸位遇到输入汉字时会重复输入 请交一个关于域的问题 整理了一个带语法高亮显示,及到处html功能的richtextbox控件 我现在做了个web系统,要求允许windows域用户自动注册,有什么建议 另外一个实现事务提交、回滚的方法 关于登陆到域的用户,不需要显示登陆界面的问题(aspx)
保护站点子目录的文件
吴建明 · 2006-04-26 · via 博客园 - 吴建明

实现访问某个站点子目录下的文件时,显示登陆页面。

1、编制httphandler
建立一个类项目MyHandler,新建一个类MyHandler。

using System;
using System.Web;

namespace MyHandler
{
    /// <summary>
    /// Summary description for NewHandler.
    /// </summary>
    public class NewHandler : IHttpHandler
    {
        public NewHandler()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        #region Implementation of IHttpHandler
        public void ProcessRequest(System.Web.HttpContext context)
        {
            string FileName = context.Server.MapPath(context.Request.FilePath);
            context.Response.WriteFile(FileName);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        #endregion
    }
}
编译得到MyHandler.dll文件。
2、建立测试项目,
加入login.aspx页面和建立scores文件夹,在文件夹中拷贝一个pdf文件。
在login登陆按钮中输入以下代码:
using System.Web.Security
FormsAuthentication.RedirectFromLoginPage(txtUserId.Text, false);

修改config文件
在<system.web>中加入
<authentication mode="Forms" >
         <forms name=".reelbook" loginUrl="Login.aspx"/>       
</authentication>

<httpHandlers>
    <add verb="GET" path="scores/*.pdf" type="MyHandler.NewHandler,MyHandler"/>
</httpHandlers>

<location path="scores">
  <system.web>
        <authorization>
            <deny users="?" />
        </authorization>
    </system.web>
</location>

3、在iis中,加入以下扩展:
 
4、现在访问http://*/testdemo/scores/tets.pdf,就会显示login.aspx登陆页面,从而保护了文件的安全。