会话超时问题 [英] Session Timeout issue

查看:76
本文介绍了会话超时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用2个按钮对会话超时进行简单测试。我已经在网上找到了一个java脚本来设置超时并显示一个窗口,其中包含一个重置计时器的选项。这是我的Default.aspx代码:

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 () {
                //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>





这是我的Default.aspx.vb代码:



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.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





我有一个带有简单显示语句的DivertPage.aspx。

当我在web.config文件中使用会话超时1分钟编译程序时,在网页上什么都不做 - 应用程序到期并带我去DivertPage.aspx。但是,当我点击testButton时,它永远不会过期。

我期待在超时20秒之前看到一个弹出窗口,要求我重置,但弹出窗口从未出现过。

有人可以请帮我理解出了什么问题。



谢谢!



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!

推荐答案

find( mpeTimeout)。show();
},超时 - 20 * 1000 );
setTimeout( function (){
window location = DivertPage.aspx;
},超时);
};
function ResetSession(){
// 重定向以刷新会话。
window location = window location .href;
}
< / 脚本 >

< / head >

< 正文 >
< 表格 id = form1 runat = 服务器 > ;
< p &G t; 在示例页面上测试超时< / p >
< div id = tabs-1 >

< asp:按钮 ID = ClickIt OnClick = btnClick runat = server 文字 = 点击 / >

< asp:按钮 ID = TestButton < span class =code-attribute> OnClick = btnClicktest runat = server 文字 = 点击新 / >

< / div >

< / form >
< / body >
< / html >
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>





这是我的Default.aspx.vb代码:



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.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





我有一个带有简单显示语句的DivertPage.aspx。

当我在web.config文件中使用会话超时1分钟编译程序时,在网页上什么都不做 - 应用程序到期并带我去DivertPage.aspx。但是,当我点击testButton时,它永远不会过期。

我期待在超时20秒之前看到一个弹出窗口,要求我重置,但弹出窗口从未出现过。

有人可以请帮我理解出了什么问题。



谢谢!



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!


这篇关于会话超时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆