开发者

What is the Intended Usage of the ASP.NET Session?

In an ASP.NET application you can store pretty much anything in the Session as long as you can handle the cost. What is the intended usage and what is most frowned upon w开发者_JAVA技巧hen using the Session to store data?


Any user specific data that has to be persistent across various pages of an application to the logged in user can stored in a session. The objects to be stored in Session need to be serializable.

Usually, it is recommended that the session should be used a little sparingly, because with an increase in number of concurrent users,the load on server memory increases and at one point, it recycles the memory causing all session data to be dumped. This causes a premature timeout of the session.


I like to use the session to hold keys, or indices into server-side data that doesn't need to be persisted between pages. That is lighter weight than persisting the whole object(s)


As of ASP.NET MVC2 TempData is stored in the session.

Some uses of it are described here: ASP.NET MVC - TempData - Good or bad practice and here Tempdata Improvements.


Session are used to persist information for each client.

Everytime a new client establishes a connection asp.net starts a new session for the newly connected client. You might want to keep some information persistent to current session of the client and display information on perform some operation based on his/her session information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜