ASP.NET Automatic logout

后端 未结 5 1213
我在风中等你
我在风中等你 2021-01-01 06:12

I am doing a group project with 4 other people. We are designing a job kiosk in ASP.NET in MVC4 with embedded c#.

I am working on having the system log the user out

5条回答
  •  清酒与你
    2021-01-01 06:50

    Here is how I do it if you are using FormsAuthentication:

    Controller Action:

    public ActionResult CheckLogin()
    {
        if (Request.Cookies["CookieName"] == null) return Json(0, JsonRequestBehavior.AllowGet);
        var cookie = Request.Cookies["CookieName"].Value;
        var ticket = FormsAuthentication.Decrypt(cookie);
        var secondsRemaining = Math.Round((ticket.Expiration - DateTime.Now).TotalSeconds, 0);
        return Json(secondsRemaining, JsonRequestBehavior.AllowGet);
    }
    

    Jquery on each page or on layout page:

    
    

提交回复
热议问题