在ASP.NET中将用户变量存储在数据库与会话中 [英] Storing user variables in database vs session in asp.net

查看:94
本文介绍了在ASP.NET中将用户变量存储在数据库与会话中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个asp.net应用程序,该应用程序将大多数数据存储在数据库中,而不是会话中。我想知道每种方法的优缺点,哪一种是更好的方法。例如,您有一个非常繁忙的站点,而不是在会话中存储用户特定的变量,而是有一个名为用户数据的数据库表,它可以存储所有用户特定的数据,这些数据可以通过查询数据库从任何页面访问。

I'm working with an asp.net application that stores most data in a database and not session. I'm wondering of the pros and cons of each and which is the better way to go. For example, you have a pretty busy site and instead of storing user specific variables in session, there is a DB table called user data and it can store all user specific data that can be accessed from any page by querying the database. Which is the better way to go, session or database?

推荐答案

有趣的问题是哪种更好的方式?如果数据在整个会话中都不重要(例如,上次浏览的页面)->会话。如果数据应该是永久性的(例如密码)->数据库。有趣的情况以及您可能提到的情况:应该是持久的但也经常使用的数据(例如,用户名)。通过这些,我倾向于将那些值从数据库复制到会话中,这使我可以在没有琐碎任务的页面中进行工作而无需数据库访问。

Interesting question. If it's data that's not important across sessions (say, last page viewed) -> session. If it's data that should be persistent (say, password) -> database. The interesting case and the one you probably refer to: Data that should be persistent but is also used often (say, the username). From these, I tend to copy those values from the DB into the session that allow me to work without database access in pages with trivial tasks.

这篇关于在ASP.NET中将用户变量存储在数据库与会话中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆