.NET WEB技术小记

通常处理程序没法使用Session的解决方法

  1. 先引用System.Web.SessionState
  2. 给ProcessRequest方法添加一个要实现的接口IRequirsSessionState

使用模板文件做为响应的内容

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); //将响应内容输出到浏览器

如何判断一个后台处理程序是由url发出的请求仍是由表单提交而发出的请求

能够表单中加一个type="hidden"的控件,如:html

<input type="hidden" name="action" value="post" />

在后台处理程序中进行判断,如:浏览器

string isPostBack = context.Request["action"];
    if (string.IsNullOrEmpty(isPostBack))
    {
        //第一次发出的请求,也就是说是由url发出
    }else{
        //由表单提交发出的
    }
相关文章
相关标签/搜索