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

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
博客园_首页
量子位
T
Tailwind CSS Blog
博客园 - Franky
G
Google Developers Blog
D
DataBreaches.Net
Vercel News
Vercel News
B
Blog
Recent Announcements
Recent Announcements
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
爱范儿
爱范儿
博客园 - 【当耐特】
The Cloudflare Blog
H
Help Net Security
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
C
Check Point Blog
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 吴建明

请讨论这个数据库该如何设计? 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登陆页面,从而保护了文件的安全。