简体   繁体   English

如何存储清单 <typed> 从Web场服务器会话中?

[英]How store List<typed> in session from web farm server?

Where I work, is having migration of several web applications (WebForm and MVC) to a web-farm. 我工作的地方是将多个Web应用程序(WebForm和MVC)迁移到Web服务器场。 The session will be managed by SQL Server. 该会话将由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. 当在某些特定情况下,会话中存储了不可序列化的List<typed>对象等时,问题就开始了。

I'm thinking in a way to refactor, in a DRY style, everything this. 我正在考虑以一种DRY风格重构这一切。

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; 所以在任何地方都可以使用: Session["mList"] = myList;

I would trade for: CustomSession.AddsInDatabase("mList", myList); 我将交易: 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? 这是一个很好的选择,还是还有其他选择?

:) :)

Is there some reason you don't want to use the SQL Server Session-State provider implemented by Microsoft? 您是否有某些原因不想使用Microsoft实现的SQL Server会话状态提供程序

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. 如果您使用自定义路线,建议您始终将会话值存储为二进制blob并在数据库中使用BinaryWriter以及SessionStateItemCollection.Serialize在调用之间进行序列化和反序列化,这样您就不必进行任何假设您要存储的对象的类型。

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 . 您可以检查来自MSDN 的自定义提供程序的示例实现,以了解实现从SessionStateStoreProviderBase继承的类所涉及的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM