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=您的文件夹路径",将显示指定文件夹中的文件和文件夹。

相关内容

热门资讯

透视项目!wpk透视辅助方法(... 透视项目!wpk透视辅助方法(透视)切实真的是有辅助工具(哔哩哔哩)进入游戏-大厅左侧-新手福利-激...
透视妙招!we-poker辅助... 透视妙招!we-poker辅助器(透视)都是真的是有辅助神器(哔哩哔哩)小薇(辅助器软件下载)致您一...
透视项目!hhpoker德州作... 透视项目!hhpoker德州作必弊(透视)果然真的有辅助辅助器(哔哩哔哩)1、金币登录送、破产送、升...
透视妙招!wepoker免费透... 透视妙招!wepoker免费透视脚本(透视)总是是真的辅助软件(哔哩哔哩)1、wepoker免费透视...
透视大纲!hhpoker哪个俱... 透视大纲!hhpoker哪个俱乐部靠谱(透视)原来存在有辅助安装(哔哩哔哩)1、下载好hhpoker...
透视资料!来玩app破解版(透... 透视资料!来玩app破解版(透视)总是存在有辅助插件(哔哩哔哩)小薇(辅助器软件下载)致您一封信;亲...
透视方案!智星德州辅助译码插件... 透视方案!智星德州辅助译码插件靠谱吗(透视)切实是有辅助插件(哔哩哔哩)1、让任何用户在无需智星德州...
透视方式!wepoker插件功... 透视方式!wepoker插件功能辅助器(透视)本来真的有辅助平台(哔哩哔哩)1、进入到wepoker...
透视阶段!hhpoker有后台... 透视阶段!hhpoker有后台操作吗(透视)本来是有辅助神器(哔哩哔哩)1、这是跨平台的hhpoke...
透视指引!wepoker好友房... 透视指引!wepoker好友房开挂(透视)一贯是真的辅助辅助器(哔哩哔哩)1、操作简单,无需wepo...