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

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;

    }

  }

}
原文地址:https://www.cnblogs.com/webenh/p/5743058.html