您的位置:首页 > 其它

Persistent cookies和Session cookies的定义与区别

2010-10-24 15:21 351 查看
Session Cookies

============

Session Cookies是临时的cookie文件, 在你关闭浏览器之后就会失效并被删除掉.

当你重启你的浏览器, 并再回到之前为你创建cookie的站点的时候, 这个站点不会认识你的. 你必须重新登录. 登录之后, 一个新的session cookie会被生成. 你的浏览信息会被存储在这个新的cookie中, 这个cookie会一直保持active的状态, 直到你再次关闭浏览器.

Session Cookie仅能被浏览器使用. 其他应用程序不能共享.

Persistent Cookies

============

Persistent Cookies会被保存在一个浏览器的一个子文件夹中, 除非手动删除或者浏览器定期清理, 否则会一直存在.

Persistent Cookie是可以在多个应用程序间共享的, 前提是这些应用程序可以访问相同的cookie store. 默认情况下Persistent Cookie的过期时间是30分钟.

如果你想延长这个时间, 需要在站点的web.config中添加如下的一行

<forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" timeout="100" />




是否启用Persistent Cookie取决于什么呢? 答案是站点的authentication provider的实现. 代码片段如下.

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
"userName",
DateTime.Now,
DateTime.Now.AddMinutes(30), // value of time out property
false, // Value of IsPersistent property
String.Empty,
FormsAuthentication.FormsCookiePath);


参考资料:

============

Are all cookies the same?

http://www.allaboutcookies.org/cookies/cookies-the-same.html

Plan authentication settings for Web applications (Windows SharePoint Services)
http://technet.microsoft.com/en-us/library/cc288081(office.12).aspx

Explained: Forms Authentication in ASP.NET 2.0

http://msdn.microsoft.com/en-us/library/ff647070.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: