代码改变世界

ashx使用session

2020-07-25 13:12  idea555  阅读(127)  评论(0)    收藏  举报

using System;
using System.Web;
using System.Web.SessionState;//第一步:引用命名空间

//第二步:实现接口
public class Login : IHttpHandler, IRequiresSessionState
{

public void ProcessRequest(HttpContext context)
{
string un = context.Request["uname"];
string pwd = context.Request["pwd"];

string json = "{\"ok\":\"0\"}";

Users u = new UsersData().Select(un, pwd);
if (u != null)
{
context.Session["user"] = un;//第三步:实现Session赋值
json = "{\"ok\":\"1\"}";
}
...