ASP.NET自定义目录浏览处理程序
创始人
2024-09-19 23:01:22
0

ASP.NET自定义目录浏览处理程序可以通过以下步骤来实现:

  1. 创建一个新的ASP.NET Web应用程序项目。

  2. 在项目中创建一个名为"CustomDirectoryBrowser"的新文件夹。

  3. 在"CustomDirectoryBrowser"文件夹中创建一个名为"CustomDirectoryBrowser.ashx"的新文件。

  4. 在"CustomDirectoryBrowser.ashx"文件中添加以下代码:

using System;
using System.Web;

public class CustomDirectoryBrowser : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string path = context.Request.QueryString["path"];
        string[] files = System.IO.Directory.GetFiles(path);
        string[] directories = System.IO.Directory.GetDirectories(path);

        context.Response.ContentType = "text/html";
        context.Response.Write("");

        // 显示文件
        foreach (string file in files)
        {
            context.Response.Write($"{System.IO.Path.GetFileName(file)}
"); } // 显示文件夹 foreach (string directory in directories) { context.Response.Write($"{System.IO.Path.GetFileName(directory)}
"); } context.Response.Write(""); } public bool IsReusable { get { return false; } } }
  1. 在项目的"Web.config"文件中添加以下代码,以将"ashx"文件映射到"CustomDirectoryBrowser"处理程序:

  
    
      
    
  

  1. 构建和运行应用程序。

  2. 在浏览器中访问"/CustomDirectoryBrowser.ashx?path=您的文件夹路径",将显示指定文件夹中的文件和文件夹。

相关内容

热门资讯

wepoker私人局透视教程!... wepoker私人局透视教程!hh poker透视器下载(透视)工具-原来曝光真的有挂1、这是跨平台...
wepoker怎么获得好牌!x... wepoker怎么获得好牌!xpoker怎么透视(透视)教程-确实揭露真的是有挂1、完成wepoke...
werplan有挂吗!wepo... werplan有挂吗!wepoker免费透视脚本(透视)工具-本来关于真的有挂1、用户打开应用后不用...
wejoker透视方法!wep... wejoker透视方法!wepoker透视有吗(透视)脚本-好像必备有挂1、很好的工具软件,可以解锁...
购买wepoker模拟器!ag... 购买wepoker模拟器!agpoker辅助(透视)app-原来教你真的是有挂购买wepoker模拟...
哈糖大菠萝能开挂吗!wepok... 哈糖大菠萝能开挂吗!wepokerplus脚本(透视)插件-果然有挂真的是有挂;哈糖大菠萝能开挂吗破...
hhpoker为什么一直输!w... hhpoker为什么一直输!wepoker免费透视(透视)工具-总是开挂存在有挂1、上手简单,内置详...
wepoker私人局透视插件!... wepoker私人局透视插件!wejoker辅助器怎么卖(透视)攻略-原来辅助是真的挂1、操作简单,...
wepoker是不是有人用挂!... wepoker是不是有人用挂!德州透视插件(透视)攻略-其实曝光是有挂wepoker是不是有人用挂辅...
这一问题亟待解决!新鸿狐辅助软... 这一问题亟待解决!新鸿狐辅助软件是真的吗,奇迹思维辅助(透视)app-一贯存在有挂1、让任何用户在无...