Pergunta

Where I work, is having migration of several web applications (WebForm and MVC) to a web-farm. The session will be managed by SQL Server.

The problem is ever legacy!

For those cases more easier of use the session, store strings, returns and etc, the code will remain untouched. The problem starts when in some specific situations, were stored List<typed> objects or the like, which are not serializable, in the session.

I'm thinking in a way to refactor, in a DRY style, everything this.

Most lists stored in the session, are collections resulting from Entity Framework queries. Honestly, I could not figure out if there is any shortcut around it. The only solution that come to mind immediately, and rapidly, would create a table in the database of legacy system and store those objects - and then create some mechanism to remove the inactive rows sporadically.

So anywhere that make use of: Session["mList"] = myList;

I would trade for: CustomSession.AddsInDatabase("mList", myList);

Taking proper care of the logged in user, time of insertion and so on.

Is it a good alternative, or are there others?

:)

Foi útil?

Solução

Is there some reason you don't want to use the SQL Server Session-State provider implemented by Microsoft?

If yes, then I'd recommend implementing a custom session-state provider. If you go the custom route, I'd recommend always storing your session values as a binary blob in the database and using a BinaryWriter along with SessionStateItemCollection.Serialize to serialize and deserialize between calls so that you don't have to make any assumptions about the type of object you are storing.

You can examine this example implementation of a custom provider from MSDN to get a feel for what kind of work is involved in implementing a class inherited from SessionStateStoreProviderBase.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top