Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
XML
<%@ 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 () {
                //Show Popup before 20 seconds of timeout.
                $find("mpeTimeout").show();
            }, timeout - 20 * 1000);
            setTimeout(function () {
                window.location = "DivertPage.aspx";
            }, timeout);
        };
        function ResetSession() {
            //Redirect to refresh Session.
            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:
VB
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.Write("page google enter")

        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!
Posted

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