对于 asp.net 中IhttpHandle,和IHttpModel中使用Session 会话

备注下:

    在asp.net中的以上两个类中需要使用会话Session保存值,并使用的话,需要继承另外一个接口

Handle 中需要继承 IRequiresSessionState  引入的 命名空间 System.Web.SessionState然后即可直接使用了

Models中 IReadOnlySessionState

令需要在初始化事件中添加相应的操作

  1. public void Init(HttpApplication context)  
  2.    {  
  3.        context.PreRequestHandlerExecute+=new EventHandler(context_PreRequestHandlerExecute);  
  4.    }  
  5.    void context_PreRequestHandlerExecute(object sender, EventArgs e)  
  6.    {  
  7.        HttpApplication app = (HttpApplication)sender;  
  8.        HttpContext con = app.Context;  
  9.        HttpSessionState session = con.Session;  
  10.        if (session .Count!=0)  
  11.        {  
  12.            string s = session ["key"].ToString();  
  13.        }  
  14.    }

 

参考 http://spance.itpub.net/25897606/viewspace-712504

IReadOnlySessionState,

posted @ 2012-11-21 13:07  楼上少年  阅读(299)  评论(0编辑  收藏  举报