THMLpage.htm 请求页
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action ="Handler.ashx">
<input type="hidden" name="ispostback" value="true" />
<input type="text" value="@value1" name="number1" /><input type="text" value="@value2" name="number2" /><input type="submit" value="=" />
<input type="text" value="@value3"/>
</form>
</body>
</html>
Handler.ashx 响应页
<%@ WebHandlerLanguage="C#"Class="Handler"%>
using System;
using System.Web;
public class Handler : IHttpHandler{
public void ProcessRequest (HttpContextcontext) {
context.Response.ContentType = "text/plain";
stringispostback = context.Request.QueryString["ispostback"];
stringnumber1 = context.Request.QueryString["number1"];
stringnumber2 = context.Request.QueryString["number2"];
stringvalue3 = "";
if(ispostback == "true")
{
value3 = (Convert.ToInt32(number1)+ Convert.ToInt32(number2)).ToString();
}
stringfullpath = context.Server.MapPath("HTMLPage.htm");
stringcon = System.IO.File.ReadAllText(fullpath);
con = con.Replace("@value1", number1);
con = con.Replace("@value2", number2);
con = con.Replace("@value3", value3);
context.Response.Write(con);
}
public bool IsReusable {
get {
returnfalse;
}
}
}