Classroom session

I have a class object where I store a list of questions. I want to keep this object in the session. I can do it:

JobApplication _application;
_application = new JobApplication(1);

Session["Application"] = _application;

      

I can also get the session like this:

JobApplication obj = (JobApplication)Session["Application"];

      

So I want to pass a class object (JobApplication _application;) to the class and establish a session in the class and return the session. Can I install and get how I do?

but I would rather pass the object to my session class and set it and get it from there. I'm not sure how to use sessions in get and set. I am new to C #

+3


source to share


2 answers


public class JobApplicantSession
{
    public JobApplication Application 
    {
        get
        {
            return (JobApplication)HttpContext.Current.Session["Application"];
        }
        set
        {
            HttpContext.Current.Session["Application"] = value;
        }
    }
}

      



+4


source


Please do please below

 public class JobApplicantSession
    {
       public JobApplicantSession(JobApplication  _application )
       {
         Session["Application"] = _application;
       }

        public JobApplication  GetApplication()
        {
         JobApplication _application = Session["Application"];
         return _application ;
        }

    }

      



Also make sure the class JobApplication

has the attribute[Serializable]

0


source







All Articles