ADOU-V

导航

ASP.NET中在一般处理程序中使用session的简单介绍

 1 <%@ WebHandler Language="C#" Class="ChangePwd" %> 
 2 
 3 using System; 
 4 using System.Web; 
 5 using System.Web.SessionState; 
 6 public class ChangePwd : IHttpHandler, IReadOnlySessionState 
 7 { 
 8 
 9     public void ProcessRequest (HttpContext context) 
10 
11    { 
12         context.Response.ContentType = "text/plain"; 
13         OperUser ou = new OperUser(); 
14         if (ou.ChangeWsPassword(context.Session["ws_user"].ToString(),context.Request.QueryString["pwd"].ToString())) 
15         { 
16             context.Response.Write("true"); 
17         } 
18         else
19         { 
20             context.Response.Write("flase"); 
21         } 
22 
23     } 
24 
25     public bool IsReusable { 
26         get { 
27             return false; 
28         } 
29     } 
30 
31 }

加上 using System.Web.SessionState;和 IReadOnlySessionState

如果您的处理程序将访问会话状态值,它必须实现 IRequiresSessionState 接口(不包含任何方法的标记接口)。 

导入using System.Web.SessionState; 

果然,只要对自定义类加上一个IRequiresSessionState标记接口就可以了,也不需要实现任何的方法。

与此,同时还有另一个接口:IReadOnlySessionState接口,用于指示Http处理程序,对Session有只读的权限,也是空接口,无需实现任何方法。

 

 


 

在一般处理程序中值继承了只读的session接口。不能设置session的

常用的session接口有:
  IReadOnlySessionState和IRequiresSessionState
  -----
  System.Web.SessionState.IReadOnlySessionState为只读会话的接口
  System.Web.SessionState.IRequiresSessionState 为可读可写会话的接口
  你可以改成IRequiresSessionState 这个接口。

posted on 2016-06-14 15:49  a-dou  阅读(464)  评论(0)    收藏  举报