I am new to asp.net. I went to the site and created a session for userid, treating this session as s1. A cookie is added (c1) to the clientβs site after 3 days.
Suppose if I close the browser without logging out and I use the same url again, then I found that the session is null, but I got a cookie (c1), after which I created a new session. But the s1 session still takes up memory on the server. This time, two sessions are on the same server, occupying memory.
I want to use an s1 session with a cookie (c1) - this is possible. or I want to delete the s1 session if the second time a request arrives.
The code I use is:
if (Session["UserInfo"] != null) { // code } else { HttpCookie HT = Request.Cookies["User"]; if (HT != null) { Session["UserInfo"] = HT["UserName"]; //Here new session is created while previous is already exist on server } else { //code } }
source share