How to remove specific session in asp.net?

前端 未结 6 1854
醉酒成梦
醉酒成梦 2020-12-28 12:54

I am facing a problem. I have created two sessions:

  1. Session[\"userid\"] = UserTbl.userid;
  2. Session[\"userType\"] = UserTbl.type;
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 13:28

    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.

提交回复
热议问题