I think the best way to go about this is like
ignatandrei suggested and use the the tempdata. This way you don't have to be concerned about writing clean up code.
An action method can store data in the controller's TempDataDictionary object before it calls the controller's
RedirectToAction method to invoke the next action. The
TempData property value is stored in session state. Any action method that is called after the
TempDataDictionary value is set can get values from the object and then process or display them. The value of
TempData persists until it is read or until the session times out. Persisting
TempData in this way enables scenarios such as redirection, because the values in
TempData are available beyond a single request.
Since you want to send records from one view to another this would be a prefect fit.
Hope this helps.
Regards,
Yorrick
Live life loosely coupled and separated of concerns
&
Don't forget to click "Mark As Answer" on the post that helped you.
it will depend on your session type (inproc or sqlserver).
first there is no notifcation to the server of the user leaving the site. the session has a timeout (usually 20 mintues) that is updated on every page request that uses session. also the session cookie has a timeout (which needs to be shorter than the server
timeout). if the session cookie timesout, a new session is created (even if the old session still exists).
with inproc sessions, when the session timeouts, dispose is called. if your session manages unmanged resourse, then you shoudlo override dispose, and call dispose on the necessary objects.
when sqlserver sessions, a sp is run which deletes all session objects whode lastmodified timestamp is less then the current time - session timeout.
SanjaySutar
Participant
1128 Points
692 Posts
best way to dispose session variables ??
May 04, 2012 12:57 PM|LINK
Hi,
I am using session variables extensively for storing Records and other objects which are specific to a page.
What is best way to destroy those session variables once i navigate to other page ??
Should i use dispose() or anything else ??
raduenuca
All-Star
24675 Points
4250 Posts
Re: best way to dispose session variables ??
May 04, 2012 01:02 PM|LINK
Session.Remove("VariableName")
Radu Enuca | Blog
ignatandrei
All-Star
134535 Points
21583 Posts
Moderator
MVP
Re: best way to dispose session variables ??
May 04, 2012 01:04 PM|LINK
you can use TempData - based on session, but set and access once.
SanjaySutar
Participant
1128 Points
692 Posts
Re: best way to dispose session variables ??
May 05, 2012 11:44 AM|LINK
Thanks for the reply.
My question here is where should i write this clean up code ???
Should i write this in dispose() method ??
Yorrick vd V...
Participant
1674 Points
301 Posts
Re: best way to dispose session variables ??
May 05, 2012 05:31 PM|LINK
Hi,
I think the best way to go about this is like ignatandrei suggested and use the the tempdata. This way you don't have to be concerned about writing clean up code.
Please take a look at the statement below, taken from: http://msdn.microsoft.com/en-us/library/dd394711.aspx
An action method can store data in the controller's TempDataDictionary object before it calls the controller's RedirectToAction method to invoke the next action. The TempData property value is stored in session state. Any action method that is called after the TempDataDictionary value is set can get values from the object and then process or display them. The value of TempData persists until it is read or until the session times out. Persisting TempData in this way enables scenarios such as redirection, because the values in TempData are available beyond a single request.
Since you want to send records from one view to another this would be a prefect fit.
Hope this helps.
Regards,
Yorrick
&
Don't forget to click "Mark As Answer" on the post that helped you.
bruce (sqlwo...
All-Star
36656 Points
5438 Posts
Re: best way to dispose session variables ??
May 05, 2012 06:53 PM|LINK
it will depend on your session type (inproc or sqlserver).
first there is no notifcation to the server of the user leaving the site. the session has a timeout (usually 20 mintues) that is updated on every page request that uses session. also the session cookie has a timeout (which needs to be shorter than the server timeout). if the session cookie timesout, a new session is created (even if the old session still exists).
with inproc sessions, when the session timeouts, dispose is called. if your session manages unmanged resourse, then you shoudlo override dispose, and call dispose on the necessary objects.
when sqlserver sessions, a sp is run which deletes all session objects whode lastmodified timestamp is less then the current time - session timeout.
SanjaySutar
Participant
1128 Points
692 Posts
Re: best way to dispose session variables ??
May 10, 2012 07:44 AM|LINK
Tried using TempData, but it is unavailable once it is read.
I want to keep the data for multiple reads. So I am using Session object.
raduenuca
All-Star
24675 Points
4250 Posts
Re: best way to dispose session variables ??
May 10, 2012 07:51 AM|LINK
You can use TempData.Keep("variableName") and this will unmark the variable for being deleted.
So
var someVar = TempData["myVar"];
TempData.Keep("myVar");
Radu Enuca | Blog