Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a asp.net website. I need to auto logout function in my application. If user is not active in the site for 15 minutes then it automatically log out and update database in login_status-0. I am using the code, if user is login then in the database login status=1. So, i need to update database login_status=1 if user is not active for 15 minutes or suddenly close the browser.

Please any one can help me......Thanks
Posted

You can set the session timeout to 15 minutes. The browser will not close - it will simply expire.
Have a look at state management - http://msdn.microsoft.com/en-us/library/ms972429.aspx[^].
 
Share this answer
 
Comments
rahul dev123 6-May-11 2:11am    
Thanks for your suggestions but i also want to update the database
Rubaba 7-May-11 10:02am    
5 for good link.
You need to set your session timeout to 15Minutes. And yes, expire only the session, it will not close the screen.
 
Share this answer
 
Comments
Rubaba 7-May-11 10:02am    
5 for good link.
 
Share this answer
 
Comments
Rubaba 7-May-11 10:02am    
5 for good link.
Monjurul Habib 9-May-11 2:29am    
thank you Rubaba.
Always its better to Create a session time limit to the user when he login's .Read the MSDN documentation at MSDN
SQL
Usually, you set the session timeout, and you can additionally add a page header to automatically redirect the current page to a page where you clear the session right before the session timeout.
<a href="http://aspalliance.com/1621_Implementing_a_Session_Timeout_Page_in_ASPNET.2">Link</a>
<pre>
<pre lang="cs">
namespace SessionExpirePage
{
    public partial class Secure : System.Web.UI.MasterPage
    {
        public int SessionLengthMinutes
        {
            get { return Session.Timeout; }
        }
        public string SessionExpireDestinationUrl
        {
            get { return "/SessionExpired.aspx"; }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.PageHead.Controls.Add(new LiteralControl(
                String.Format("<meta http-equiv='refresh' content='{0};url={1}'>",
                SessionLengthMinutes*60, SessionExpireDestinationUrl)));
        }
    }
}




SQL
The SessionExpireDestinationUrl should link to a page where you clear the session and any other user data.
When the refresh header expires, it will automatically redirect them to that page
.
 
Share this answer
 
you can use session and login authentication functionality....!!
 
Share this answer
 
Hi there,

Think a bit out of the box? :)

Set the session to expire in 15 minutes, so the user will have to log in again, so the browser part is taken care of.

Now you want to update the database. Instead, why don't you store the last activity date and time of the user. Each time a post back happens, check whether the difference between the the "LastActivityDate" and the current date is greater than 15 minutes, if so do whatever you want (update the database, log the user out, redirect the user, etc.) If the time difference is less than 15 minutes, update the "LastActivityDate" to the current date and time :)

Furthermore, you can define a global constant, based on which you set the session timeout duration and perform other calculations. Therefore, in a case where you want to change the duration from 15 minutes to 5 minutes or 6 hours, you just have to update that constant. If I were you I'd define a constant public const int MaxIdleTime = 900; I.e. keep the constant in seconds :)

Hope this helps :) Regards
 
Share this answer
 
 
Share this answer
 
Comments
Sandeep Mewara 29-Aug-12 2:40am    
What if the browser is still open and no one exits the page? OP's situation will still be an issue.... right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900