动态页面替换文本。Replace
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
//获取要操作的模板的路径.
string filePath = context.Request.MapPath("ShowInfo.html");//获取文件的物理路径。在Asp.net中,对文件或文件夹进行操作一定要获取物理路径。
//读取模板文件中的内容。
string fileContent=File.ReadAllText(filePath);
//用户具体的数据替换模板文件中的占位符。
fileContent = fileContent.Replace("$name","替换成名字").Replace("$pwd","123");
//将替换后的内容输出给浏览器。
context.Response.Write(fileContent);
context.Response.Write("<b>adfsdf</b>");
}
get请求,post请求。服务器端接收数据。
<%@ WebHandler Language="C#" Class="AddInfo" %>
using System;
using System.Web;
public class AddInfo : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
///string userName=context.Request.QueryString["txtName"];//get请求接收的是表单元素name属性的值
// string userPwd=context.Request.QueryString["txtPwd"];
string userName = context.Request.Form["txtName"]; //post请求
string userPwd = context.Request.Form["txtPwd"];
context.Response.Write("用户名是:"+userName+",密码是:"+userPwd);
}
public bool IsReusable {
get {
return false;
}
}
}