zoukankan      html  css  js  c++  java
  • Persistent cookies和Session cookies的定义与区别

    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

  • 相关阅读:
    Java
    Java
    Java
    Java
    NYOJ 127 星际之门(一)
    BNUOJ 1013 YC大牛的判题任务
    BNUOJ 1011 人工智能?
    HDU 1035 Robot Motion
    HDU 1214 圆桌会议
    NYOJ 86 找球号(一)
  • 原文地址:https://www.cnblogs.com/awpatp/p/1859756.html
Copyright © 2011-2022 走看看