如何在控制器中进行无休止的会话

How to make an endless session in controller

会话可能会自行结束 10 到 15 分钟,我希望只要网络打开,会话就会继续。 我想要一种通过 controller

的简化方式
  [HttpPost]
        public ActionResult Verify(Users acc, string fullname, string roll)
        {
            DesigenTeemOfMagoubEntities db = new DesigenTeemOfMagoubEntities();
            var f_password = HelperClass.EncryptPassword(acc.Password);
            var data = db.Users.Where(s => s.Username.Equals(acc.Username) && 
            s.Password.Equals(f_password)).ToList();
            count = 0;
            if (data.Count() > 0)
            {
                var category = db.Users.Where(s => s.Username == acc.Username).First();
                acc.FullName = category.FullName.ToString();
                acc.Roll = category.Roll.ToString();
                acc.lang = category.lang.ToString();
                acc.bransh = category.bransh.ToString();
                Session["UserName"] = acc.Username.ToString();
                Session["Password"] = HelperClass.EncryptPassword(acc.Password).ToString();
                Session["FullName"] = acc.FullName.ToString();
                Session["Roll"] = acc.Roll.ToString();
                Session["lang"] = acc.lang.ToString();
                Session["bransh"] = acc.bransh.ToString();
                return RedirectToAction("mob", "Account");
            }
            else
            {
                ViewBag.error = "Login failed";
                return RedirectToAction("Logincheck");
            }
        }

您可以在 web.config 中设置会话超时,如下所示。会话超时的默认值为 20 分钟。

建议你给个大号。您可以提及的最大数量是 525,600 minutes (1 year)。请参阅 this 了解有关会话超时的更多详细信息

<configuration>
  <system.web>
     <sessionState timeout="20"></sessionState>
  </system.web>
</configuration>