A brief introduction to using session in general handlers in ES0en.NET

  • 2020-07-21 07:28:49
  • OfStack


<%@ WebHandler Language="C#" Class="ChangePwd" %> 

using System; 
using System.Web; 
using System.Web.SessionState; 
public class ChangePwd : IHttpHandler, IReadOnlySessionState 
{ 

    public void ProcessRequest (HttpContext context) 

   { 
        context.Response.ContentType = "text/plain"; 
        OperUser ou = new OperUser(); 
        if (ou.ChangeWsPassword(context.Session["ws_user"].ToString(),context.Request.QueryString["pwd"].ToString())) 
        { 
            context.Response.Write("true"); 
        } 
        else
        { 
            context.Response.Write("flase"); 
        } 

    } 

    public bool IsReusable { 
        get { 
            return false; 
        } 
    } 

}

Add using System. Web. SessionState; And IReadOnlySessionState

If your handler is going to access session state values, it must implement the IRequiresSessionState interface (tag interface that does not contain any methods).


Import using System. Web. SessionState;
Sure enough, just add an IRequiresSessionState tag interface to the custom class, and you don't need to implement any methods.
At the same time, there is another interface: the IReadOnlySessionState interface, which instructs the Http handler, has read-only permissions on Session, is also an empty interface, and does not need to implement any methods.

Related articles: