Click here to Skip to main content
Click here to Skip to main content

Extending Session and Timed Alert Message in ASP.NET

, 14 Apr 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
This article about how to extend your ASP.NET session and alert the user based some predefined time

This article shows how to display an alert message and prompt the user whether he wants to extend the session. If the user clicks OK, then it will automatically increase the session, else it will close the session with a warning message.

You can also change and update the code based on your requirements, this is just sample to show how to extend the session and show a timed-out alert message.

<script language="javascript" type="text/javascript">
    AlertTimeOut = 0.25 * 60 * 1000; // Milliseconds, Alert Message       
        WarnTimeOut = 0.25 * 60 * 1000; //  Warn Message before 5 min of session out
        setTimeout("WarnUser();", WarnTimeOut);
        //setTimeout("AlertUser();", AlertTimeOut);
         function AlertUser()
        {
           alert('Your session has been expired, please save your data outside the system [copy the data in word document].');        
        }
        function WarnUser()
        {
            var currentTime = new Date()
            var hours = currentTime.getHours()
            var minutes = currentTime.getMinutes()
            if (minutes < 10){
            minutes = "0" + minutes
            }            
            if(hours > 11){
            var tempTime = hours + ":" + minutes + "PM"
            } else {
            var tempTime = hours + ":" + minutes + "AM"
            }
            var ans = confirm("Your login session is about to expire in 5 minutes.Do you want to extend it? - Date: " + tempTime);
 
            if (ans)
            {
                var oImage = new Image;
                oImage.src = "tempdummy.gif" + Math.random(); 
                setTimeout("WarnUser();", WarnTimeOut);                
            }
            else
            {
                 setTimeout("AlertUser();", AlertTimeOut);
            }
        }
        </script>

License

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

Share

About the Author

Daniel Vincent
Software Developer (Senior) Al Tayer Group
United Arab Emirates United Arab Emirates
I have done B.Tech in Information Technology and working as
a Senior Software Engineer. Has been working with .Net Technologies since 2006

Comments and Discussions

 
Questionimage required?? PinmemberMember 1104661429-Aug-14 20:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 14 Apr 2011
Article Copyright 2011 by Daniel Vincent
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid