我是 asp.net 的新手。我登录该站点并为用户 ID 创建了会话,将此会话视为 s1。将 cookie (c1) 添加到客户端站点,有效期为 3 天。
假设如果我在没有注销的情况下关闭浏览器并再次使用相同的 url,那么我发现 session 为 null,但我得到了 cookie (c1),然后我创建了一个新 session。但是会话 s1 仍然占用服务器上的内存。意味着这次两个会话在同一台服务器上占用内存。
我想将会话 s1 与 cookie (c1) 一起使用 - 是否可能。或者如果第二次请求到来,我想删除会话 s1。
我使用的代码是:
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
}
}