ASP.NET MVC

Session.Clear(), Session.Abandon(), Session.RemoveAll()

Often asked by users, how to kill sessions? how to remove sessions?, what is the difference between Session.Clear(), Session.Abandon() and Session.RemoveAll()? which is the best?. etc.

So, here is the full explanation of all methods.

Session.Clear and Session.RemoveAll is like a twin, Both will immediately remove all stored values from session, but the session object still in the memory. In this, Session_OnEnd will not execute/hit.

Session.Abandon in actual it’s not clear the values immediately, it just indicates the session to be abandoned at the end of the current request. We can continue to read the values for the rest of the request. If we write to the session later in the request, the new value will be dropped at the end of the request with no indication. Session_OnEnd executes at the end of the request.

Syntax

  • To clear Session
Session.Clear();

  • To remove Session
Session.RemoveAll();

  • To abandon Session.
Session.Abandon();

As we can see, In Clear and RemoveAll/Remove method  Session immediately remove values from request session wherein Abandon Session values is still in session till the end of a request.

Are you searching for a Dedicated and experienced .NET developer to help you design a visually attractive and interesting website? Identifying your project’s requirements is the first step in outsourcing a .NET developer. It is then simple to determine the amount of education and experience. If the job description is more detailed then it is simpler to locate dedicated .NET Developers in India.

If you are looking to store values in the session, you can find here.

Faisal Pathan

Faisal Pathan is a founder of TheCodeHubs, .NET Project Manager/Team Leader, and C# Corner MVP. He has extensive experience with designing and developing enterprise-scale applications. He has good skills in ASP.NET C#, ASP.NET Core, ASP.NET MVC, AngularJS, Angular, React, NodeJS, Amazon S3, Web API, EPPlus, Amazon MWS, eBay Integration, SQL, Entity Framework, JavaScript, eCommerce Integration like Walmart, Tanga, Newegg, Group-on Store, etc. and Windows services.

View Comments

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago