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-state values. This is a marker interface and has no methods.

 

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"]);
        }
    }
}

 

 

Like above ,we can easily get  session information....

Okay ,if you have  other good method,share it with us.......

 

 

posted @ 2009-06-11 23:49  Haisen  Views(253)  Comments(0)    收藏  举报