The Mask The Mask - 3 months ago 26
ASP.NET (C#) Question

set the timeout for a specific session

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"] //expire in 14minutes
Session["baa"] //expire in 30minutes


I'm wanting solve this case,if possible not using cookies.

Thanks in advance!

Tim Tim
Answer

You can configure the timeout for a session in the Web.config file:

<configuration>
    <sessionstate mode="inproc"
                  cookieless="true"
                  timeout="14" />
</configuration>

This is the default mode (InProc) for ASP.NET. As rockinthesixtring said in his comment, you can't configure the timeout for individual objects in the session, just the session as a whole.

ASP.NET Session State Overview