备注下:
在asp.net中的以上两个类中需要使用会话Session保存值,并使用的话,需要继承另外一个接口
Handle 中需要继承 IRequiresSessionState 引入的 命名空间 System.Web.SessionState然后即可直接使用了
Models中 IReadOnlySessionState
令需要在初始化事件中添加相应的操作
- public void Init(HttpApplication context)
- {
- context.PreRequestHandlerExecute+=new EventHandler(context_PreRequestHandlerExecute);
- }
- void context_PreRequestHandlerExecute(object sender, EventArgs e)
- {
- HttpApplication app = (HttpApplication)sender;
- HttpContext con = app.Context;
- HttpSessionState session = con.Session;
- if (session .Count!=0)
- {
- string s = session ["key"].ToString();
- }
- }
参考 http://spance.itpub.net/25897606/viewspace-712504
IReadOnlySessionState,