【问题标题】:ASP .NET Timeout implementation with Display Timeout error message带有显示超时错误消息的 ASP .NET 超时实现
【发布时间】:2017-07-24 21:44:10
【问题描述】:

我想在我的 ASP .net Web 应用程序上实现超时功能。这样用户将在 60 分钟后被重定向到超时消息。 我在 webconfig 中使用了以下内容

<sessionState timeout="60"></sessionState>

我在网上找不到此任务的任何有用示例。 我想知道是否有办法在客户端用 jQuery 或 Javascript 实现这个?

【问题讨论】:

  • 你试过计时器课吗? msdn.microsoft.com/en-us/library/…
  • 不,我需要在 ASP .Net 中完成
  • 哪种 ASP.NET - ASP.NET Core、ASP.NET MVC 或 ASP.NET Web 窗体?
  • 它是 ASP .NET Web 窗体
  • 我建议存储每个请求的时间,如果当前时间和存储时间之间的差异> 60,则重定向。

标签: javascript c# jquery asp.net session-timeout


【解决方案1】:

通过实现在clinet端执行的jQuery函数来解决问题,并将用户重定向到超时页面。

     $(document).ready(function () {
        var timeInSeconds = 30
        var timeoutTimer = timeInSeconds * 1000;
        var timeoutToRefresh = window.setTimeout(timeoutfunction, timeoutTimer)


        var isPostBack = ("true" === "<%= Page.IsPostBack ? "true" : "false" %>");

        if (!isPostBack) {
            $('#cost').hide();
            $('#imgCost').attr("src", "../../Design/Images/iconPlus.png");
        } else {
            $('#imgCost').attr("src", "../../Design/Images/minus_icon.png");
        }
    });

    var timeoutfunction = function () {
        window.location.replace('/CustomErrorPage.aspx')
    };

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 2019-11-27
    • 2021-05-30
    • 2017-03-23
    • 1970-01-01
    • 2014-04-28
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    相关资源
    最近更新 更多