【问题标题】:C# ASP.NET Core 2.0 + Azure AD authentication: auto sign out after user's inactivity for certain periodC# ASP.NET Core 2.0 + Azure AD 身份验证:用户在一段时间内不活动后自动注销
【发布时间】:2018-07-16 21:12:51
【问题描述】:

我有一个使用 Azure Active Directory 身份验证的 ASP.NET Core 2.0 Web 应用程序。如果他/她在 15 分钟内不活动,我需要它来注销用户。我该怎么做?

【问题讨论】:

  • 您想将它们从您的应用程序或 Azure AD 中注销?
  • 我想从应用程序和 Azure AD 中退出。
  • 实际上来自应用程序。

标签: c# azure-active-directory asp.net-core-2.0


【解决方案1】:

除了在 _Layout.cshtml 中使用 JS 脚本之外,没有找到任何其他方法来解决这个问题:

<script>
    $(function () {
        $("body").on('click keypress', function () {
        ResetThisSession();
        });
    });

    var timeInSecondsAfterSessionOut = 900; // change this to change session time out (in seconds).
    var secondTick = 0;

    function CheckPage() {
        if (window.location.pathname == "/Account/SignedOut") {                
            return;
        } else {                
            StartThisSessionTimer();
        }
    }

    function ResetThisSession() {
        secondTick = 0;
    }

    function StartThisSessionTimer() {
        secondTick++;
        if (secondTick > timeInSecondsAfterSessionOut) {
            clearTimeout(tick);
            window.location.href = '@Url.Action("SignOut", "Account")';
            return;
        }
        tick = setTimeout("StartThisSessionTimer()", 1000);
    }

    CheckPage();

</script>

【讨论】:

  • 两个问题: 1. 它把我带到一个Azure“你想退出哪个帐户”页面,看起来几乎与登录页面相同。 2. 按浏览器的后退按钮让我回到应用程序 - 它不会使会话过期。
猜你喜欢
  • 2018-09-15
  • 1970-01-01
  • 2013-09-23
  • 2018-12-19
  • 2017-07-10
  • 2018-06-23
  • 2013-04-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多