Search This Blog

Tuesday, March 19, 2013

How can use a Session variable from a .cs file.


How can use a Session variable from a .cs file.

I have a Session variable defined in login time in application and ues this session on another .cs file (which doesn't have a corresponding .aspx file), error accour

on page : "The name 'Session' does not exist in the current context".

Question is that how can I access the Session variable on cs file ???

namespace : using System.Web.SessionState
Interface : IRequiresSessionState


using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.SessionState;

///IRequiresSessionState enable session in Class file

public class Class1:IRequiresSessionState
{
    public Class1()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public void getSession(string key)
    {
        if (HttpContext.Current.Session[key] != null)
        {
            string sessionID= HttpContext.Current.Session[key].ToString();
        }
    }
}

No comments :