1

I am new to .net technology, i am confused in the concept of session , simply i want to know when session will be expired?

1) is it timeout of session

(or)

2) user being idle.

please clarify my doubt anyone.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
sumanthb
  • 25
  • 1
  • 6
  • It is the timeout of the session. Every time a user requests something from the server the session is refreshed. If you want a session to stay alive when the user is idle for long periods, you need to make sure the browser issues a request at regular intervals. I do this by having a hidden iframe in a header control (that appears on every page) with a javascript timer running that reloads the (empty) page in the iframe every 15 minutes. – Martin Smellworse Jul 31 '14 at 06:28
  • Refer Adam Sills's answer from http://stackoverflow.com/questions/3515947/losing-session-state – Earth Jul 31 '14 at 06:33
  • 1
    @MartinSmellworse - that sounds like an awful solution. Better would be to solve your problems without such a heavy reliance on session state, which is going to get lost no matter how hard you try to prevent it. – Ant P Jul 31 '14 at 06:34
  • @AntP - well it works for me on a site with thousands of users that have my application open all day but often minimized. The only time the session disappears is if the users lose connection and they all have one-click log-ins to get back in. The alternative is passing log-in data around all the time in querystrings and checking credentials on every page. Big hit on the database. – Martin Smellworse Jul 31 '14 at 06:51

3 Answers3

1

There are a lot of reasons for session loss. To name a few,

  • Application Pool is recycled. - We will know this looking at the system logs
  • IIS/worker process is restarted. - System logs will tell this as well
  • Application Domain is restarted. - We need to monitor for application restarts for the ASP.NET counter in perfmon to check this. Few reasons for application restarts include
    • Bin folder of the application is touched by some application
    • Web.config or the machine.config is touched
    • Global.asax file is touched
  • Antivirus is running
  • Something in the code is causing session loss, it can be anything. You will need to look into the code to have a fix on this.
  • And many more...

  • Based on your options, session will expire from session timeout, as user being idle will also cause session timeout after particular quantum of time.

source: MSDN Blog

Community
  • 1
  • 1
Abhinav
  • 523
  • 6
  • 17
0

Session in asp.net will expire after the timeout, by default the timeout is 20 minutes [msdn reference].

This timeout is sliding timeout that means if user shows any activity within these 20 minutes the countdown again starts from 20 minutes. So in order for expiration of session, user should sit idle for 20 minutes.

You can change this timeout in your Web.config's tag as shown below.

     <sessionState mode="InProc" cookieless="false" regenerateExpiredSessionId="true" timeout="35">
       <providers>...</providers>
     </sessionState>
Siddhant Swami
  • 323
  • 1
  • 3
  • 14
0

Session is something you should avoid if at all possible. It doesn't scale well, and is unreliable. If you do use Session, it should be short lived because you cannot guarantee how long a session will stay active for InProc sessions.

In any event, Sessions can be either a timeout, or idle depending on your settings. If you enable sliding timeout, it effectively becomes an idle timeout. If you do not enable sliding timeout, then it's a flat time based timeout.

However, again, just because the timeout may be 20 minutes there is no guarantee that it will be available for 20 minutes.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291