【问题标题】:Stop the page refreshing when the session has not ended ASP.NET MVC C#会话未结束时停止页面刷新 ASP.NET MVC C#
【发布时间】:2020-02-20 23:04:54
【问题描述】:

我编写了代码以在页面空闲 2 分钟时刷新页面(借助 stackoverflow 帮助)。代码工作正常,但我的问题是当用户在页面上工作时,会话结束时应用程序仍会刷新。我需要帮助来重置我的代码中的会话,以在页面不空闲时停止应用程序重置。

Web.config

<system.web>
   <sessionState timeout="2" /> 
</system.web>

_布局页面

<script>
  //session end reset page
  var sessionTimeoutWarning = @Session.Timeout- 1;

  var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000;

  setTimeout('SessionEnd()', sTimeout);

  function SessionEnd() {
    window.location = "/Home/SessionExpired";
  }
</script>

家庭控制器

public ActionResult SessionExpired()
{
    Session["conectionstring"] = null; 
    Session["patientid"] = null;
    Session.Clear();
    Session.Abandon();
    return RedirectToAction("Index", "Home");
}

【问题讨论】:

    标签: c# asp.net-mvc session


    【解决方案1】:

    您可以在 web.config 文件中尝试 slipExpression=true

    <authentication mode="Forms">
      <forms loginUrl="login.aspx"
        name="loginPage"
        cookieless="UseCookies"
        slidingExpiration="true" />
    </authentication>

    【讨论】:

    • 如果我使用的是 ,我该如何使用您的建议。我正在使用 Active Directory 对用户进行身份验证谢谢
    • 滑动过期仅适用于 FormsAuthetication,因为它与 cookie 有关。过期 cookie 被丢弃后。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2017-11-16
    相关资源
    最近更新 更多