想实现 http://localhost/download/任意目录/任意文件名 都调用 http://localhost/download.aspx来进行过滤,允许下载后才将实际文件输出。
download不存在真实的目录,想用HttpHandler实现,不知道怎么做。web.config里也不知道怎么加。
大侠给点提示!

解决方案 »

  1.   

    你不需要httphandle,只要在global.asax里写代码就可以了,就是地址重写技术,handle一般是对文件名过滤用的以下就是改变http://.../foo/quotes/page1.aspx
    http://.../foo/quotes/page2.aspx
    http://.../foo/quotes/page3.aspx为http://.../foo/rewritepath.aspx?id=1
    http://.../foo/rewritepath.aspx?id=2
    http://.../foo/rewritepath.aspx?id=3的例子<script language=C# runat="server">
    void Application_BeginRequest (Object sender, EventArgs e)
    {
        // TODO: Convert a path of the form
        // .../quotes/page1.aspx into a path of the form
        // .../rewritepath.aspx?id=1
        //
        HttpContext context = HttpContext.Current;
        string oldpath = context.Request.Path.ToLower ();    string token = "/quotes/page";
        int i = oldpath.IndexOf (token);
        int len = token.Length;
         if (i != -1) {
            int j = oldpath.IndexOf (".aspx");
             if (j != -1) {
                string id =  oldpath.Substring (i + len, j - (i + len));
                string newpath =             oldpath.Replace (token + id + ".aspx", "/rewritepath.aspx?id=" + id);
                context.RewritePath (newpath);
            }
        }
    }
    </script>