0

I want to logout my site automatically in asp.net, when my site is in idle state. I set my sessiontimeout as "10 min" in web.config by using authentication. For Example: If my site was in idle state for 9 minutes, then i used mysite (ie.,make my site inactive mode to active mode). Then after, timer will have to start with new session (like it has to start with 0:0:0). If my session timeout(i.e., exceeds 10 mins) site will have to automatically logout.. Please guide me?? Any ideas????

PremKumar
  • 1
  • 1
  • 3

3 Answers3

0

You can use form authentication and set the session-timeout for your purpose.

<configuration>
  <system.web>
     <sessionState timeout="10"></sessionState>
  </system.web>
</configuration>

This will make the session time out of 10 minutes. If any request comes before 10 minutes then it will again increase (total of 10) minutes.

More Details
How to set session timeout in web.config

You can use slidingExpiration="false" in you web.config file if you wan only 10 minutes.

More details

According to MSDN

When the SlidingExpiration is set to true, the time interval during which the authentication
cookie is valid is reset to the expiration Timeout property value. This happens if the user 
browses after half of the timeout has expired. For example, if you set an expiration of 20 
minutes by using sliding expiration, a user can visit the site at 2:00 PM and receive a cookie 
that is set to expire at 2:20 PM. The expiration is only updated if the user visits the site 
after 2:10 PM. If the user visits the site at 2:09 PM, the cookie is not updated because half 
of the expiration time has not passed. If the user then waits 12 minutes, visiting the site at 
2:21 PM, the cookie will be expired.
Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

It's hard to understand what you are trying to do. Why is this question tagged with "javascript" and "ajax"?

Session state does not necessarily relates to forms authentication. I could have been issued a persistent cookie from your site and it doesn't matter for how long your site stays idle I will still be able to send an authenticated request to your site...because I have a persistent cookie. Even more, you can even restart site or your app pool...I still wont be logged out of your website.

If you want to log users out of your website after 10 minutes of inactivity and you are using Forms Authentication, then issue your users with a cookie that expires after 10 minutes, see web.config example below

<forms 
   timeout="10">
</forms>

if you want to "reset" the expiration value, then use sliding expiration like this in web.config

<forms    
   timeout="10"
   slidingExpiration="true">
</forms>

There many more values you can specify for forms authentication. Read the MSDN documentation...

http://msdn.microsoft.com/en-us/library/1d3t3c61(v=vs.85).aspx

I think you are a bit confused. Hopefully, this answer makes things a bit clearer for you my friend

Leo

Leo
  • 14,625
  • 2
  • 37
  • 55
0

Check this out exactly what are you looking for:

http://philpalmieri.com/2009/09/jquery-session-auto-timeout-with-prompt/ and https://github.com/philpalmieri/jquery-idleTimeout

Khalil
  • 139
  • 2
  • 1