Click here to Skip to main content
13,904,914 members
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 12 Apr 2011
Licenced CPOL

Extending Session and Timed Alert Message in ASP.NET

, 13 Apr 2011
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);                
                 setTimeout("AlertUser();", AlertTimeOut);


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


About the Author

Daniel Vincent
Software Developer (Senior) Al Tayer Group
United Arab Emirates United Arab Emirates
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

Questionimage required?? Pin
Member 1104661429-Aug-14 19:51
memberMember 1104661429-Aug-14 19:51 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 14 Apr 2011
Article Copyright 2011 by Daniel Vincent
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid