Server Side State Management:
Session State: ASP.NET allows you to save values by using session state. This is an instance of the HttpSessionState class. Session state provides a place to store values that will persist across page requests. You can store values that need to be persisted for the duration of a user's session in session variables. These variables are unique to each user session and can be accessed in any ASP.NET page within an application. You can set and access session information from within an ASP.NET application. Values stored in Session are stored on the server and will remain in memory until they are explicitly removed or until the Session expires. You can set and access session information from within an ASP.NET application. For example //Assign a value to the myvariable session variable. Session["myvariable"] = "somevalue"; //Retrieve the value of the myvariable session variable. string myString; if (Session["myvariable"] != null) myString = (string)Session["myvariable"]; It is important to remember that session variables are now objects. Thus, to avoid a run-time error, you should check whether the variable is set before you try to access it. Session variables are automatically discarded after they are not used for the time-out setting. The Session Timeout is adjustable through a web.config setting but increasing the timeout value can put memory pressure on your server that may be undesirable. < sessionState timeout="number of minutes" /> Other commonly used Session methods are: Session.Abandon(): removes the Session and all items that it contains Session.Clear(): removes all items from the Session Session.RemoveAll(): removes all items from the Session Session.Remove("itemName"): removes the item that was stored under the name "itemName" ASP.NET supports three modes of session state: InProc: (The Default) Session state exists within the process the web is using. StateServer: Session data is sent to the configured stateserver service. SQLServer: Session data is store in the configured sql server database. Note You can use all three modes with in-memory cookie or cookieless session ID persistence. You can use session state to accomplish the following tasks:
Uniquely identify browser or client-device requests and map them to an individual session instance on the server.
Store session-specific data on the server for use across multiple browser or client-device requests within the same session.
Raise appropriate session management events. In addition, you can write application code leveraging these events.
No comments:
Post a Comment