views:

72

answers:

2

I have a fairly complex ASP MVC set of controls that set a data filter (account ID range, cost range, carrier, dates etc). This also creates a data table object with the standard result set type object.

The user might wonder away from the page and then come back. I want to restore the previous filter control states and also pull the current result set.

What is the standard ASP MVC method for storing the user session state? I do have access to a SQLServer database. One idea is to store the filter view object and current result in the cache.

I do not need to restore the state between session visits (they close the browser and come back at another time.)

A: 

Storing Session State is the right key word.

http://msdn.microsoft.com/en-us/library/ms972429.aspx

http://www.devarticles.com/c/a/ASP/Maintaining-Session-State-With-ASP/

You need to simply grab the session state variable and store it somehow, then retreive it somehow. That might be a lot of work, and there might be a built in way to make it happen since you have an MS SQL Server right there. But I dont know about hooking those things up, so I'd write the session object to an objectstream hooked into the database. You can query for it later.

EDIT: On the other hand, since you said you don't need it to be restored between visits, maybe you just want to make the lease duration of this one a lot longer than it is. Sounds like they are timing out? Tell it to hang onto connections for a few more hours. Unless they close the page, theyll get a new logon at the front if the browser deleted cookies.

Karl
I am trying to stay within the MVC ASP model and was just curious what the best practice was. It looks like though we have cut down on viewstate and other states, we still need to rely on the session/cookies to persist state. I think I will just dump their filter into the database based on their account ID and dump the result set into the cache. If the cache deletes the result set, I will just requery with their last filter settings.
Kenoyer130
I ended up going with a repository pattern class that isolated the use of the session to store the page view state.
Kenoyer130
A: 

I believe you just want to persist the filter values and not the query results right? If so, you may want to save those to a string and persist them in a cookie. You could use the asp session too. There are some scalability drawbacks with session, but it is often the simplest option.

Matt Wrock