I am new to asp.net. I login the site and created session for userid consider this session as s1.
Add an cookie (c1) to client site with expiration of 3 days is added.
Suppose if i close the browser without logout and again i use the same url then i found session is null but i got cookie (c1) then i created a new session. But session s1 is still occupies memory on server. Means this time two sessions are on the same server occupying memory.
I want to use session s1 with the cookie (c1) – is it possible. or i want to delete session s1 if second time the request comes.
The code I used 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
}
}
IE generate a new session id on each request. So when u close your browser old Session id is get lost, so browser sends request with new session id. That’s why u are not able to get value of session.
But on server it occupies server memory , which is cleared by server after session time out.
Firefox sends request with same session id on each request, u can get your session Id even if u close your browser tab.