ASP.NET: Remove Session in asp.net using C# and VB.NET.

Aman Sharma
0
We know HTTP is stateless Protocol, it means a new instance of webpage class created each time the page post back. It can’t hold data on page. So to maintain data between different pages, we use Session. Session provides the facility to store information on server.

In this article I will explain how to remove sessions in ASP.NET.

Store Information in Session in C#:
//Storing UserName in Session
Session["SessionName "] = txtUser.Text;

In VB.Net
'Storing UserName in Session
Session("SessionName ")= txtUser.Text


Remove sessions in asp.net using C#:

To remove particular session.
//Remove Particular session
Session.Remove("SessionName");

or
Session["SessionName"] = null;

To remove all sessions created in Application:
//Remove all sessions
Session.RemoveAll();
or
 Session.Abandon();


Remove sessions in VB.NET:

To remove particular session :
'Remove Particular session

Session.Remove("SessionName ")
or
Session("SessionName ") = Nothing

To remove all sessions created in the application:
'Remove all sessions
Session.RemoveAll()
or
Session.Abandon()


Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !