I am facing a problem. I have created two sessions:
Session[\"userid\"] = UserTbl.userid;
Session[\"userType\"] = UserTbl.type;
you can use Session.Remove() method; Session.Remove
Session.Remove("yourSessionName");
A single way to remove sessions is setting it to null;
Session["your_session"] = null;
There is nothing like session container , so you can set it as null
but rather you can set individual session element as null or ""
like Session["userid"] = null;
There are many ways to nullify session in ASP.NET. Session in essence is a cookie, set on client's browser and in ASP.NET, its name is usually ASP.NET_SessionId
. So, theoretically if you delete that cookie (which in terms of browser means that you set its expiration date to some date in past, because cookies can't be deleted by developers), then you loose the session in server. Another way as you said is to use Session.Clear()
method. But the best way is to set another irrelevant object (usually null
value) in the session in correspondance to a key. For example, to nullify Session["FirstName"]
, simply set it to Session["FirstName"] = null
.
HttpContext.Current.Session.Remove("sessionname");
it works for me
Session.Remove("name of your session here");