set the timeout for a specific session

前端 未结 4 448
旧时难觅i
旧时难觅i 2021-01-22 14:13

How I can set the timeout for a session specific in ASP.NET? it is possible? I have two or more sesions in my web application, I need set:

Session[\"foo\"] //exp         


        
4条回答
  •  [愿得一人]
    2021-01-22 14:58

    for specific session lets say you want to make timeout for this session Session["foo"] =14 min you can do like this

    DateTime timenow=DateTime.now;
    DateTime timeafter14min=timenow.AddMinuits(14);
    
    if(DateTime.Now>timeafter14min)
    {
     HttpContext.Current.Session["foo"]=null;
    }
    

    session not expired but cleared

提交回复
热议问题