c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
.Net

How to clear session in asp.net?

| | ASP , ASP-NET , CSharp

In this article I will explain how to clear session in asp.net with an example. If you want to remove the specific session then you can set it as null or “”. Here I have set it for userId to null(e.g: Session["userId"] = null;). Session.Abandon(); will destroy the session.

You could use it for example when the user logs out.

   public ActionResult LogOut()

        {
            FormsAuthentication.SignOut();
            Session.Abandon(); // it will clear the session atthe end of request
            return RedirectToAction("Login", "Admin", new { area = "" });

        }