Managing Persistent User State in Your ASP.NET
Managing Persistent User State in Your ASP.NET
In this post i want to give very simple and clear information about state management in asp.net.
ASP.net Provides different ways managing states between the user requests.
There are nine ways to manage state in asp.net those are
- Application
- Cookies
- Form Post / Hidden Form Field
- QueryString
- Session
- Cache
- Context
- ViewState
- Web.config and Machine.config Files
Persistence Method | Who Needs the Data? | For How Long? | How Much Data? | |
---|---|---|---|---|
Application | All users | Until the next application restart | Can be almost any size—it will only be stored once | |
Cookie | One user | As short as desired, or for months or even years if the user doesn't delete their cookies | Minimal, simple data | |
Form Post | One user | For the next request (can be reused across many requests) | Virtually any size—the data is sent back and forth with every page | |
QueryString | One user or one group of users | For the next request (can be reused across many requests) | Minimal, simple data | |
Session | One user | As long as the user is active, plus a timeout period (typically 20 minutes) | Can be almost any size, but should be minimized since every user has their own separate session store | |
Cache | All users or a subset of users | As long or as short as needed | Can be used for large or small, simple or complex data | |
Context | One user | This request only | Can hold large objects, but typically does not since it is often used for every request | |
ViewState | One user | One Web form | Minimal; as with Form Post, this data is sent back and forth with every page | |
Config file | All users | Until the configuration file is updated | Can hold a lot of data; usually organized as many small strings or XML structures |
Hope this will helps you