SESSION IN A CLASS

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
 1037  View(s)
Ratings:
Rate this:

I have a class object where i m storing a list of questions in. I want to save this object in a session. I can do this:

JobApplication _application;

_application = new JobApplication(1);

Session["Application"] = _application;

i can also get the session by this:

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

So, I want to pass in the class object( JobApplication _application;) into a class and set the session in the class and return a session. Can i set and get like i am doing?

but i would rather pass in the object into my session class and set it and get it from there.

I am not sure how to use sessions in get and set . 

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Session in a class

    Hi Ashish, 


    try this:

    public class JobApplicantSession

    {

        public JobApplication Application

        {

            get

            {

                return (JobApplication)HttpContext.Current.Session["Application"];

            }

            set

            {

                HttpContext.Current.Session["Application"] = value;

            }

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!