Skip to main content

Posts

Showing posts with the label session

How to remove an item from session in asp.net

Remove an item from session Asp.net session state allows us to store and retrieve values for a user as the user navigates asp.net pages in a website. HTTP is a stateless protocol. Session state makes an asp.net application stateful that allows us to save, update, remove, and read user data. We can delete an item from the session state collection by using HttpSessionState Remove() method as Session Remove(). This Session Remove(name) method requires passing a parameter. This parameter name is 'name' and its data type is String. The Remove() method exists under System.Web.SessionState namespace. The 'name' parameter value is the name of the item to delete from the session state collection. If the session state collection does not contain an element with the specified name (that passes by parameter), the collection remains unchanged. No exception is thrown. The following asp.net c# example code demonstrates to us how can we re...

How to clear the current session data in asp.net

Session Clear() Method The ASP.NET application uses the session state to store and retrieve the user's data. The application store data when the user navigates ASP.NET pages on a website. We can add an item (variable) to the session state collection using Session Add() method and we can remove a variable from the session state collection by using Session Remove() method. ASP.NET session state collection store each item as a key-value pair. In this pair, the key is the item name and the value is the specified item's value. HttpSessionState class’s Clear() method allows us to remove all keys and values from the current session state collection. We can use this method in an ASP.NET application as the Session Clear() method. This method has no parameter and it has no return value. The Session Clear() method exists under System.Web.SessionState namespace. The following ASP.NET C# example code demonstrates to us how can we clear the curr...

How to add an item to the session in asp.net

Add an item to the session state collection ASP.NET session is a state management tool that stores and retrieves values for a user when the user navigates to a website. We can add and delete items from session state collection by .NET framework built-in methods. HttpSessionState class’s Add() method allows us to add a new item (variable) to the session state collection. We can call this method in an asp.net application as Session Add() method. This Session.Add(name, value) method requires passing two parameters to add an item to the session state collection. The first parameter name is 'name' and the second parameter name is 'value'. The 'name' parameter value is the name of the item to add to the session state collection. And the 'value' parameter is the value of the item to add to the session state collection. The name parameter data type is String and the value parameter data type is Object. this Session Add()...

How to use Session.Abandon() method in asp.net

Session Abandon() method to cancel current session HttpSessionState class’s Abandon() method allows us to cancel the current session. We can call this method in an ASP.NET application like Session.Abandon() method. This method has no parameter and it has no return value. Abandon() method exists under System.Web.SessionState namespace. This Session Abandon() method destroys all the objects stored in a session object and releases their resources. When a session time out, the server also destroys all objects from this session. In this case, we do not need to call the Session Abandon() method. If we call the Session Abandon() method, the current session is no longer valid. But a new session can be started. Session Abandon() method causes the SessionStateModule End event to be raised which occurs when a session ends. A new SessionStateModule Start event will be raised in the next HTTP request. The Start event occurs when a session is created. SessionStateMod...

How to use session state in asp.net

How to use Session The Session is an important state management tool in the asp.net application. Session state allows us to store and retrieve values for a user when navigating asp.net pages in an asp.net web application. Web server treats each HTTP request for a web page as an independent request because HTTP is a stateless protocol. The Web server does not know about the variables of the previous page request. Asp.net session state can identify the same browser request during a limited time window as a session and allow to persist values for that session. Asp.net have more state management tools such as application state, profile properties, cashing, view state, cookies, and query string. The Session variables are stored in a SessionStateItemCollection object that we can expose through the HttpContext Session property. The HttpContext Session property gets the HttpSessionState object for the current HTTP request. Session property allows us to have progr...