I am trying to do a simple test on session Timeout with 2 buttons. I have included a java script I found online to set the timeout and show a window with an option to reset the timer. This is my Default.aspx code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link type="text/css" href="MyStyle.css" rel="stylesheet" />
<title>Session Timeout</title>
<script type="text/javascript">
function SessionExpireAlert(timeout) {
var seconds = timeout / 1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function () {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
setTimeout(function () {
$find("mpeTimeout").show();
}, timeout - 20 * 1000);
setTimeout(function () {
window.location = "DivertPage.aspx";
}, timeout);
};
function ResetSession() {
window.location = window.location.href;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p>Testing timeout on a sample page</p>
<div id="tabs-1">
<asp:Button ID="ClickIt" OnClick="btnClick" runat="server" Text="Click It" />
<asp:Button ID="TestButton" OnClick="btnClicktest" runat="server" Text="Click It new" />
</div>
</form>
</body>
</html>
This is my Default.aspx.vb code:
Imports System.Configuration
Imports System.Web.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not Me.IsPostBack Then
Session("Reset") = True
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
Dim section As SessionStateSection = DirectCast(config.GetSection("system.web/sessionState"), SessionStateSection)
Dim timeout As Integer = CInt(section.Timeout.TotalMinutes) * 1000 * 60
ClientScript.RegisterStartupScript(Me.GetType(), "SessionAlert", "SessionExpireAlert(" & timeout & ");", True)
End If
End Sub
Sub btnClick(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("http://www.google.com")
End Sub
Sub btnClicktest(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("testing timeout")
End Sub
End Class
I have a DivertPage.aspx with a simple display statement.
When I compile the program with session timeout 1 min in my web.config file, and do nothing on the webpage - the application expires and takes me to the DivertPage.aspx. But, when I click on testButton, it never expires.
I was expecting to see a pop-up window before 20 seconds of the timeout asking me for a reset, but the pop-up never came up.
Can someone please help me to understand what is going wrong.
Thanks!