How to call Handler's Session on ashx page

In aspx, you can directly use Session["Name"] to assign and get values. In ashx, you have to inherit the interface IRequiresSessionState . Then use!

accomplish:

public class UserInfo : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        var userinfo = context.Session["userinfo"];
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

  

The following code example checks the current HTTP Handler property to determine whether read and write access is required for session state values.

bool requiresSession = false;if (Context.Handler is IRequiresSessionState)
  requiresSession = true;
 

Article Citation: http://code365.club/Article?id=19

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324585971&siteId=291194637