Timeout Alert Issue....Javascript Function with ASP.net application
-
Good Morning, I am trying to write a simple time out javascript to accompany an ASP.net application. The default time out for the application is 20 minutes. Currently, when it does time out, it reverts to an ugly error page. I would rather that it either logs the user off or simply sends him to the login or index page. Although I have found some very seemingly simple samples, I cannot get anything to work. I do not know if it makes a difference, but I am using an internal (<Iframe>) to rotate pages within a main page. I do not why that should make a difference since the session value is based on the session and not the page. Either way, I have tried posting the script on both the Main page that displays the frame and on the inserted frame page as well. It makes no difference. These are the two scripts that I have tried: Style 1 is supposed to give the option to take the user to a new page if it is not responded to: function warnuser() { if (confirm("There has been no activity for some time.\nClick 'OK' if you " + "wish to continue your session,\nor click 'Cancel' to log out.\nFor your " + "security if you are unable to respond to this message\nwithin 2 minutes you " + "will be logged out automatically.")) { //post the page to itself document.location.href = "Main.aspx" } else { document.location.href = "Index.aspx" } } Style 2 is simpler and simply posts a warning: function SessionAlert() { alert("Your Session will time out in 19 minutes"); } setTimeOut("SessionAlert", 1 * 60 * 1000); I tried setting the second one for just a minute just to see if it would work. It doesn't. Following is the setting that is deployed on the web.config page in the ASP.net applcation (and it does time out in 20 minutes): <sessionState mode="InProc" cookieless="false" timeout="20" /> Any assistance is greatly appreciated....Pat
-
Good Morning, I am trying to write a simple time out javascript to accompany an ASP.net application. The default time out for the application is 20 minutes. Currently, when it does time out, it reverts to an ugly error page. I would rather that it either logs the user off or simply sends him to the login or index page. Although I have found some very seemingly simple samples, I cannot get anything to work. I do not know if it makes a difference, but I am using an internal (<Iframe>) to rotate pages within a main page. I do not why that should make a difference since the session value is based on the session and not the page. Either way, I have tried posting the script on both the Main page that displays the frame and on the inserted frame page as well. It makes no difference. These are the two scripts that I have tried: Style 1 is supposed to give the option to take the user to a new page if it is not responded to: function warnuser() { if (confirm("There has been no activity for some time.\nClick 'OK' if you " + "wish to continue your session,\nor click 'Cancel' to log out.\nFor your " + "security if you are unable to respond to this message\nwithin 2 minutes you " + "will be logged out automatically.")) { //post the page to itself document.location.href = "Main.aspx" } else { document.location.href = "Index.aspx" } } Style 2 is simpler and simply posts a warning: function SessionAlert() { alert("Your Session will time out in 19 minutes"); } setTimeOut("SessionAlert", 1 * 60 * 1000); I tried setting the second one for just a minute just to see if it would work. It doesn't. Following is the setting that is deployed on the web.config page in the ASP.net applcation (and it does time out in 20 minutes): <sessionState mode="InProc" cookieless="false" timeout="20" /> Any assistance is greatly appreciated....Pat
The following javascript will simply run in background and redirect the user whereever you want - (The '3000' value is in milliseconds.) var t=setTimeout("document.location.href ='somewhereelse.aspx'",3000); Note this method is client side and works on the users browser. Clients can sometimes turn off javascript.. server side maybe needed. I won't go into the server side options here - too many! This codeproject article however is excellent for giving you a through introduction: Beginners Introduction to State Management Techniques in ASP.NET[^] I think where you're having problems is the iframe though. Your time condition needs to sit on either one or the other. In your case I would suggest the main page - the parent page to the iframe. Set a timer - client or server side here and the child iframe will have to inherit the command.