0

I wants to create session in my project.

i want to know the information about session,its syntax, and method to create it.

first i searched it in google and other websites but no any basic solution found.

so does anyone tell me how to and where to create session in mvc3 Asp.Net C#.

Thank you in advance.

1 Answer 1

9

If you want to add data to the session you can use

Session["your key"] = your value or object;

to retrieve data you can use

var Val = Session["your key"];

if you want to store and get strongly typed objects you can add them in the same way and just cast them when you receive

Session["your key"] = new YourObject();

YourObject obj = (YourObject)Session["your key"] ;
3
  • @stranger, accept the answer or post comments if you want something different/better
    – bjan
    Commented Feb 29, 2012 at 13:22
  • @bjan I also wants suggestions for where to place this code. and yes i m using Aspx view engine. Different answers then above and detailed answers will also accepted.
    – Dip
    Commented Mar 1, 2012 at 6:48
  • 4
    @stranger, there are best practices for session management, google it. Go to codeplex and download active released MVC projects with high rating and number of participants and see if you could figure out how they are managing sessions, if you cant then it is highly recommended to read some books on MVC (though there would be more than MVC). No body is going to teach you here so do it on your own, people are here to help you for specific problems not to teach. So, learn swimming before jumping into the sea otherwise ... you know
    – bjan
    Commented Mar 1, 2012 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.