context.Response.ContentType = "text/html"; string path = context.Server.MapPath("loginTemplate.htm");//找出静态文件loginTemplate.htm在磁盘的完整路径 string html = System.IO.File.ReadAllText(path);//读出其内容 string username="michael"; html = html.Replace("@username", username);//替换模板文件中的占位符@username context.Response.Write(html); //将响应内容输出到浏览器
能够表单中加一个type="hidden"的控件,如:html
<input type="hidden" name="action" value="post" />
在后台处理程序中进行判断,如:浏览器
string isPostBack = context.Request["action"]; if (string.IsNullOrEmpty(isPostBack)) { //第一次发出的请求,也就是说是由url发出 }else{ //由表单提交发出的 }