asp.net 读取一个文本文件,并输出到网页显示 通过 一般处理程序实现

用这个可以做模板首页进行输出,也可以自已自定义进行扩展

 

    //得到读取到的文本到string中

    string resultText = System.IO.File.ReadAllText(filePath);

 

public class RedFileSend : IHttpHandler

{

  public void ProcessRequest(HttpContext context)

  {

    //从服务器相对路径中得到文件真实路径

    string filePath = context.Server.MapPath("/temp/test1.html");

    //得到读取到的文本到string中

    string resultText = System.IO.File.ReadAllText(filePath);


    //设置MIME类型

    context.Response.ContentType = "text/plain";

    //进行输出

    context.Response.Write(resultText);

  }


  public bool IsReusable

  {

    get

    {

      return false;

    }

  }

}

 

相关文章:

  • 2021-07-25
  • 2021-12-02
  • 2021-06-09
  • 2022-01-20
  • 2022-12-23
  • 2021-05-17
  • 2021-07-23
  • 2021-08-28
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-08-26
  • 2021-07-16
  • 2021-08-04
  • 2021-12-30
  • 2022-12-23
相关资源
相似解决方案