Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store whole model class members in session

In a newly created MVC4 application, I would like to store all the USERProfile members in a session such that I can access all the values after the user logs in. But Session array object only proposes 2 alternative

Session[int]/Session[string]

I need to retrieve

Session['username']; Session['age']; etc

anything existing in that class.

like image 381
Asp Asp Avatar asked Feb 18 '13 20:02

Asp Asp


1 Answers

You can store

Session["UserProfile"]=UserProfile; // User Profile being an object

The caveat, is when you retrieve your profile you must cast it:

UserProfile profile = (UserProfile) Session["UserProfile"]
like image 138
Dave Alperovich Avatar answered Oct 08 '22 12:10

Dave Alperovich