How can we get session in the non-page class
Today ,One of my colleagues asked me a question about :"How to get session in the non-page class ?"
In fact,It's easy to get session information ,if you inherit a interface in the current class.![]()
Here is IRequiresSessionState Interface (System.Web.SessionState):Specifies that the target HTTP handler
requires read and write access to session
How can we use it...?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Demo
{
public class GetSession:System.Web.SessionState.IRequiresSessionState
{
public string Test()
{
return Convert.ToString(HttpContext.Current.Session["SessionId"]);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Demo
{
public class GetSession:System.Web.SessionState.IRequiresSessionState
{
public string Test()
{
return Convert.ToString(HttpContext.Current.Session["SessionId"]);
}
}
}
Like above ,we can easily get session information....
Okay ,if you have other good method,share it with us.......

浙公网安备 33010602011771号