日期:2014-05-17  浏览次数:20353 次

Handler中存的session 在aspx页面丢失了
Handler 代码如下:
<%@ WebHandler Language="C#" Class="Login" %>

using System;
using System.Web;
using BLL;
using MODEL;
using System.Web.SessionState;
public class Login : IHttpHandler,IReadOnlySessionState{
   
  public void ProcessRequest (HttpContext context) {
  context.Response.ContentType = "text/plain";
  string id = context.Request["id"];
  string pwd =context.Request["pwd"];
  UserInfo us = new UserInfoManage().login(id, pwd);
  if (us.UserId !=0)
  {
  context.Session["login"] = us;
  UserInfo u = (UserInfo)context.Session["login"];
  context.Response.Write("0");
  }
  else
  {
  context.Response.Write("1");
  }
   
  }
 
  public bool IsReusable {
  get {
  return false;
  }
  }

}

aspx页面后台代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MODEL;
public partial class Min : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  UserInfo u = (UserInfo)Session["login"];
  if (Session["login"] == null)
  {
  Response.Redirect("Login.htm");
  }
  if (!IsPostBack)
  {
   
  }
  }
}

在handler中存的session经过 在handler中的获取 证明 session中确实存入了东西 但是 为什么在 aspx页面中就显示session是空的呢 ???
求解 求大神 该怎么解决呢

------解决方案--------------------
IReadOnlySessionState

楼主应该还不能理解什么是ReadOnly
------解决方案--------------------
ReadOnly,中文意思是“只读”
------解决方案--------------------
那需要实现IRequireSessionState接口