【发布时间】:2011-02-22 23:59:47
【问题描述】:
我的 cookie 有问题。我通过 LDAP 对用户进行身份验证,只要浏览器保持打开状态,用户就不必重新登录该工具。只要浏览器打开,他们甚至可以关闭标签页。
但是,当用户关闭浏览器时,cookie 就会被删除。我已经为此搜索了很多谷歌,但我无法获得任何解决方案,例如 this one 或 that one。
这是他们在我的登录页面上进行身份验证后的设置:
String encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//Create a cookie, and then add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
//Add expiration date to the cookie
authCookie.Expires = DateTime.Now.AddMonths(1);
//Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);
//You can redirect now.
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
我的 Web.Config 如下所示:
<authentication mode="Forms">
<forms loginUrl="Logon.aspx" timeout="43200" name="adAuthCookie" path="/" slidingExpiration="true" />
</authentication>
无论我做什么,ASP.NET_SessionId 和 adAuthCookie cookie 总是设置为“当我关闭浏览器时”过期。 我想避免我的用户在关闭浏览器时总是必须登录,而是每月只登录一次。
【问题讨论】:
-
您的
authTicket是什么样的?您使用的是什么会员服务提供商? -
authTicket 看起来很正常,CookiePath 为“/”,Expired false,IsPersistent true 等...我能看到的唯一奇怪的事情是到期日期设置为 1 小时后。至于会员提供者,我对此仍然很陌生,但我不相信在这种情况下我会使用它。
标签: c# asp.net cookies forms-authentication