大型 ASP.NET 应用程序的 SQL Server State 以及编写自己的自定义存储提供程序的优势
背景
我们有一个大型的 ASP.NET 应用程序,并使用大量会话,如数据集、数据表等。 我们希望支持此应用程序的网络场,因此我们希望将会话状态保存在 sql server 中。 我成功地将所有必需的数据存储到 SQL 服务器中,并且所有数据也都正常。 我们支持的数据库是 SQL Server 2005-Sql Server 2008。 我们必须在会话中存储数据表和数据集,即使我们知道这会有点昂贵。
我想向其他开发人员询问
- 使用自定义存储提供程序存储数据是否有任何优势。 (调试或错误查找或未来证明等方面的任何帮助)
- 或者我只是更改网络配置并使所有类可序列化以使其工作。
- 使用 C# 代码使所有相关类可序列化的任何自定义方法。
- 任何更好的方法都可以通过更改一个或多个类来干预 .net 在 sql server 中存储数据的过程(更改 Web 配置的默认过程)并使其变得更好。
谢谢,
Background
We have a large asp.net application and uses a lot of sessions like datasets, datatables etc.
We want to support web farms for this application, so we want to save the session state in sql server.
I am successfully storing all the required data into the sql sever and getting all the data fine as well.
Our supported database is SQL Server 2005-Sql Server 2008.
We have to store datatables and datasets in sessions, even we know it is going to be bit expensive.
Question
- I want to know from other developers is there any advantage of using Custom Store Provider to store data. (any help in debugging or error finding or future proofing etc.)
- Or i just change the web config and make all the classes serializable to make it work.
- Any custom way to make all the related classes serializable using c# code.
- Any better way to intervene the process used by .net to store data in sql server (default process on changing web config)and make it better, by changing one or more classes.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会将您的业务对象标记为
[Serialized]
。我认为它应该比存储数据表/数据集精简得多。使您的类可序列化的最佳方法是简单地用
[Serializing]
装饰它们,我认为除此之外您不需要任何其他东西。如果您使用具有粘性会话的负载均衡器,我实际上会使用
LocalStateServer
因为它应该比SqlServer
执行得更快I would go with marking your business objects as
[Serializable]
. I think it should be a lot leaner than storingdatatables/datasets
.The best way to make your classes serializable is to simply decorate them with
[Serializable]
I don't think you need anything else besides that.If you use a load balancer with sticky sessions, I would actually go with
LocalStateServer
as it should perform faster thanSqlServer
我认为你可以支持你的观点2。
没有神奇/自动化的方法可以将所有类更改为可序列化,您可以使用属性方式或接口方式,但在某些类中,您可能需要一些修复或更改,具体取决于什么是属性类型。
除此之外,一旦一切都可序列化,一切都应该顺利工作,是的,您触摸
web.config
,一切都应该工作。如果其中一些对象不是特定于用户的,但可以在用户之间共享,则可能的替代方案是 appFabric,如果您配置缓存集群(可能包含在多台计算机中),则可以将对象保存在该缓存中,但正如我之前说过这取决于您的应用程序,这些对象是否绝对是用户特定的,因此必须位于会话中而不是共享缓存中?看看这个答案:AppFabric vs System.Runtime.Caching
I think you can go for your point 2.
there is no magic/automated way to change all your classes to be serializable, either you use the attribute way or the interface way but in some classes you could need some fixes or changes depending on what are the property types.
apart from that everything should work smoothly once everything is Serializable and yes, you touch the
web.config
and all should work.if some of those objects are non user specific but can be shared among users, a possible alternative could be appFabric, if you configure a cache cluster (which could consist in multiple machines), you can then save objects in that cache, but as I said before this depends on your application, are those objects absolutely user specific so MUST be in the session and not in a shared cache? have a look at this answer: AppFabric vs System.Runtime.Caching