我的Cookie存在问题。我通过LDAP对用户进行身份验证,只要浏览器保持打开状态,用户就不必重新登录到该工具。只要浏览器处于打开状态,他们甚至可以关闭标签。Cookie不会持续
但是,当用户关闭浏览器时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饼干始终设置为“当我关闭浏览器时”。 我想避免我的用户在关闭浏览器时始终需要登录,而是每月只做一次。
你的'authTicket'看起来像什么,你使用的是什么会员供应商? – Nimrod 2011-02-23 00:49:36
authTicket看起来很正常,CookiePath为“/”,Expired为false,IsPersistent为true等等。我能看到的唯一奇怪的事情是Expiration日期设置为1h后。至于会员供应商,我仍然是新手,但我不相信我在这种情况下使用了一个。 – LanFeusT 2011-02-23 01:24:37