ASP.NET MVC身份验证cookie

3
我的网络应用程序身份验证 cookie 在一天后超时,当我再次尝试登录时。我正在尝试通过 Nokia 浏览器和 Internet Explorer 访问应用程序,并且两者的行为都相同。
这是我的登录过程:
    [HttpPost]
    [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
                      Justification = "Needs to take same parameter type as Controller.Redirect()")]
    public ActionResult LogOn(LogOnModel model, string returnUrl)
    {
        if (MembershipService.ValidateUser(model.UserName, model.Password))
        {
            //FormsService.SignIn(model.UserName, model.RememberMe);
            FormsAuthenticationTicket Authticket = new
                        FormsAuthenticationTicket(1,
                        model.UserName,
                        DateTime.Now,
                        DateTime.Now.AddYears(1),
                        true,
                        "",
                        FormsAuthentication.FormsCookiePath);

            string hash = FormsAuthentication.Encrypt(Authticket);

            HttpCookie Authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

            if (Authticket.IsPersistent) Authcookie.Expires = Authticket.Expiration;

            Response.Cookies.Add(Authcookie);

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return Redirect(returnUrl);
            }
            return RedirectToAction("Index", "Home");
        }
        ModelState.AddModelError("", "The user name or password provided is incorrect.");

        // If we got this far, something failed, redisplay form
        return View(model);
    }

我的 web.config 设置:

<forms loginUrl="~/consignment/Account/LogOn" timeout="2880" protection="All" name=".consignmentauthadmin"/>

我正在尝试:

    [HttpPost]
    [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
                     Justification = "Needs to take same parameter type as Controller.Redirect()")]
    public ActionResult LogOn(LogOnModel model, string returnUrl)
    {
        if (MembershipService.ValidateUser(model.UserName, model.Password))
        {
            //FormsService.SignIn(model.UserName, model.RememberMe);
            FormsAuthenticationTicket Authticket = new
                        FormsAuthenticationTicket(1,
                        model.UserName,
                        DateTime.Now,
                        DateTime.Now.AddYears(1),
                        true,
                        "",
                        FormsAuthentication.FormsCookiePath);

            string hash = FormsAuthentication.Encrypt(Authticket);

            HttpCookie Authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

            if (Authticket.IsPersistent) Authcookie.Expires = Authticket.Expiration;

            Response.Cookies.Add(Authcookie);

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return Redirect(returnUrl);
            }
            return RedirectToAction("Index", "Home");
        }
        ModelState.AddModelError("", "The user name or password provided is incorrect.");

        // If we got this far, something failed, redisplay form
        return View(model);
    }

我不希望身份认证在我退出应用程序之前过期。我做错了什么吗?


我没有看到任何问题,也许你需要打开你的cookie并通过浏览器阅读它,以查看你放入了哪些数据以及日期是否正确。然后也许是你的浏览器删除了它,或者找不到它。 - Aristos
我已经读取了cookie,并且这是我8小时前收到的信息。 cookie详细信息: 过期日期:2011年7月20日上午12:00:00 已过期:否今天早上我再次尝试时,发现cookie已过期。Web应用程序正在虚拟目录下运行,所以它可能会从根目录中获取到过期时间吗? - ace
如何在服务器C#或客户端Javascript中读取cookie? - PreguntonCojoneroCabrón
1个回答

2
尝试查看您的Web服务器IIS应用程序池,它具有默认设置的“应用程序刷新”功能。 关闭它……这应该可以解决您的问题。

@ace,你解决了吗? - PreguntonCojoneroCabrón

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接