检查身份验证票证到期而不影响它

 辰小坏2602938945 发布于 2023-03-19 07:08
  • php
  • 我正在尝试实现一个Web应用程序项目,我的网页可以使用AJAX检查服务器的身份验证票证到期日期/时间.

    我正在使用带有slidingExpiration的表单身份验证.

    我遇到的问题是我无法弄清楚如何检查值而不重置它.我创建了一个简单的页面 - CheckExpiration.aspx - 下面是代码背后的代码:

      private class AjaxResponse
      {
         public bool success;
         public string message;
         public string expirationDateTime;
         public string secondsRemaining;
         public string issueDate;
      }
    
      protected void Page_Load(object sender, EventArgs e)
      {
         AjaxResponse ar = new AjaxResponse();
         JavaScriptSerializer js = new JavaScriptSerializer();
    
         if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
            FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
            string expiration = id.Ticket.Expiration.ToString();
    
            TimeSpan timeRemaining = id.Ticket.Expiration - DateTime.Now;
    
            ar.success = true;
            ar.expirationDateTime = expiration;
            ar.issueDate = id.Ticket.IssueDate.ToString();
            ar.secondsRemaining = timeRemaining.Minutes.ToString() + ":" + timeRemaining.Seconds.ToString();
         }
         else
         {
            ar.success = false;
            ar.message = "User not authenticated";
         }
    
         string output = js.Serialize(ar);
         Response.Write(js.Serialize(ar));
    
      }
    

    我每秒都使用ajax在我的应用程序的Master页面中调用此页面.超过身份验证到期的中途点,到期时间将重置.

    我该如何防止这种行为?我可以在请求的标题中做些什么吗?

    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    热门标签
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有