Home >Backend Development >C#.Net Tutorial >A brief introduction to using session in general handlers in ASP.NET

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

高洛峰
高洛峰Original
2017-01-07 09:51:001596browse

<%@ 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; 
        } 
    } 

}

Plus using System.Web.SessionState; and IReadOnlySessionState

If your handler will access session state values, it must implement the IRequiresSessionState interface (a tagged interface that does not contain any methods).


Import using System.Web.SessionState;
Sure enough, just add an IRequiresSessionState mark interface to the custom class, and there is no need to implement any methods.
At the same time, there is another interface: the IReadOnlySessionState interface, which is used to instruct the Http handler to have read-only permissions on the Session. It is also an empty interface and does not need to implement any methods.

For more related articles on the simple introduction of using session in general processing programs in ASP.NET, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn