除了视图状态之外还有其他方式存储数据源吗?
如果数据库表中不存在数据,我有一个以编程方式创建数据表的页面。我必须在回发期间的许多事件中使用此数据表。数据表可能包含数百条记录,并且可能有多个用户访问同一页面(当然每个用户的数据源不同)。我将数据表存储在视图状态中,但我担心这种做法会使页面更重。有没有其他方法可以跨回发保留数据表。代码很长,所以我无法在这里复制并粘贴它。
使用会话将再次使整个应用程序变得更重......那么它是比视图状态更好的选择吗?
I have a page on which data table is created programmatically if the data is not there in the database tables. I have to use this data table in many events during postbacks. The data table may contain hundreds of records and there may be multiple users accessing the same page(Of course with different data source for each user). I am storing the data table in view state but I am afraid that this practice will make the page heavier. Is there any other way to preserve the data table across postbacks.The code is very long so I can not copy and past it here.
Using session will again make the whole application heavier...So is it better choice over viewstate??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该使用
会话
。此外,还可以使用Application
或Cache
,但您必须在页面上生成并存储唯一的密钥,以消除来自不同用户的请求之间可能存在的干扰。You should use
Session
. Also it's possible to useApplication
orCache
but you'll have to generate and store a unique key on your page to negate possible interferention between requests from different users.在您的情况下,视图状态可能会变得非常大,并且会损害页面加载性能。恕我直言,最好的办法是修改您处理回发事件的方式。
集群环境有一些缺陷。
为了快速修复,我通常将视图状态存储在服务器上。请参阅此页面以了解相关信息...
In your case the view state can get very big and will hurt page load performance. IMHO the best thing would be to revise the way your are handling the post back events.
clustered invironment it has some pitfalls.
For a quick fix I usually store the View State on the server. Refer to this page to read about it... http://aspguy.wordpress.com/2008/07/09/reducing-the-page-size-by-storing-viewstate-on-server/
可能您需要将数据存储在 Cache 对象中
May be you need to store the data in the Cache object
如果每个用户的数据表不同,您应该使用
Session
或者可以使用Cache
,假设为每个用户创建不同的 Cache 对象。但是,如果数据表非常大,将其存储在内存中而不是直接数据库访问可能不是一个好主意。
If the data table is different for each user, you should use
Session
or you could useCache
, assumed to make a different Cache object for each user.But if the data table is very big probably is not a good idea to store it in memory instead of direct db access.
如果数据是特定于用户的,那么您可以使用 Session。但是,在进程外会话状态的情况下,您可能会遇到问题,因为所有数据都需要整理回来并重新整理。从会话存储中发出。
否则,缓存是一个不错的选择,但您需要根据典型使用场景选择缓存期限和过期策略(并且还需要优雅地处理缓存过期场景)。
另一种选择是将数据推送到临时文件中 - 但是,在这种情况下,您需要管理文件清理等。
If data is user specific then you can use Session. However, in case of out of process session state, you may have issues because all that data needs to be marshaled back & forth from session store.
Otherwise Cache is a good option but you need to choose cache period and expiration policy on typical usage scenarios (and also need to handle cache expiry scenario gracefully).
Yet another option is to push the data into temp file - however, in such case, you need to manage file clean up etc.