
正文
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;}}}






