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

高洛峰
Release: 2017-01-07 09:51:00
Original
1562 people have browsed it

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

}
Copy after login

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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template