Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to show popup to user when session is about to expire and redirect to user when he clicks ok...how to do it?...plz help...
Posted

1 solution

Hai
Just use aleart message to show time expiry,Try this,pls add this javascript in MVC4 View MasterPage,then only it work all child page,u can add this in each page also,but master page is common so better to add in master page.Here time wait for 15 mins,u can change ur expiry time

JavaScript
<script type="text/javascript">



               var logoutUser = false;
               var timeoutHnd = null;
               var logouTimeInterval = 15 * 60 * 1000; // 15 mins
               function onuser_activite() {
                   if (logoutUser) {
                       ;
                   }
                   else {
                       ResetLogOutTimer();

                   }
               }
               function OnTimeoutReached() {
                   logoutUser = true;
                   alert("You have been automatically Log Off from the system !");
                   window.location.href = "Logout.aspx";

               }
               function ResetLogOutTimer() {
                   clearTimeout(timeoutHnd);
                   // set new timer
                   timeoutHnd = setTimeout('OnTimeoutReached();', logouTimeInterval);
               }


               document.body.onclick = onuser_activite;
               timeoutHnd = setTimeout('OnTimeoutReached();', logouTimeInterval);
           </script>
 
Share this answer
 
v4
Comments
Member 9579525 14-Mar-14 4:18am    
when this script will call?
Aravindba 14-Mar-14 4:24am    
this script fires when website ideal for 15 mins,u can change time level for ur check purpose
var logouTimeInterval = 5000; // 5 secs
if website ideal for 5 secs it show time expiry msg and redirect to logout page ,again that logout page redirect to login page,why here use logout page bcz of need to clear session ,catch ect
Member 9579525 14-Mar-14 7:16am    
can we write this script in _Layout.cshtml and if i use this script then don't we have to write the code <sessionstate timeout="15"> in web.config
Member 9579525 14-Mar-14 8:24am    
even if i am giving less time e.g 5 sec then also it taking to long time show alert..is anywhere i have to set tme?
Aravindba 14-Mar-14 8:36am    
did u leave it ideal ? or something u click any place of website

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