.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"的控件,如:

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

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

    string isPostBack = context.Request["action"];
    if (string.IsNullOrEmpty(isPostBack))
    {
        //第一次发出的请求,也就是说是由url发出
    }else{
        //由表单提交发出的
    }
posted @ 2019-03-02 15:02  框框A  阅读(168)  评论(0编辑  收藏  举报