Session和Cookie之间的差异. [英] differences between Session and Cookie.which one prefer in real time

查看:84
本文介绍了Session和Cookie之间的差异.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是.net

推荐答案


的新开发人员 Cookie和会话之间的区别
Cookies存储在用户浏览器中的一条数据,可以在商店Username & Password 上使用,因此用户不必在每次访问时都重新登录到您的网站,Cookie可以将信息保留在用户的浏览器,直到删除或过期
Sessions 允许在用户打开浏览器的同时访问和传递信息.
Cookies的问题某些浏览器不支持Cookies或被用户禁用
会话更多会话会浪费您的服务器资源,它可能会崩溃
最好的问候
M.Mitwalli
Hi ,
Difference between cookies and sessions
Cookies a piece of data stored in the user''s browser it can use on store Username & Password so user do not have to re-login to your website every time they visit , Cookies can keep information in the user''s browser until deleted or Expired
Sessions allowing access and passing information while the user has their browser open .
Problem of Cookies Some browser not supporting Cookies or it disable by user
Session More session more wast resource in your sever and it may crash
Best Regards
M.Mitwalli


我的规则是:

1)如果可以,请使用URL参数存储状态,因为它提供了最可预测和可扩展的网络行为"
2)..如果不合适,请使用基于URL的会话,因为它提供的行为比cookie会话更可预测
3)..如果不合适,请使用Cookie,因为它易于缩放
4)..如果不合适,请使用基于Cookie的会话,因为,..其他方法均无效

Cookie由客户端浏览器存储,并在每次请求来自相同Cookie域(通常是相同的服务器名称或域)的网页时从客户端发送回服务器.可以将Cookie设置为生存很短时间,也可以生存很长一段时间(包括永远).

会话是服务器端存储,通常存储在服务器的ram或磁盘上.每次相同的客户端返回服务器时,服务器端会话存储都将加载/可用.必须使用唯一的URL参数或cookie来识别客户端,以便您可以找到其服务器端会话状态.

Cookie易于在多个Web服务器上扩展,因为客户端会存储并重新生成每个请求的cookie,而不管负载平衡情况下将其发送到哪个服务器.服务器相似性负载平衡可以在一定程度上弥补这一缺陷,但也有其自身的缺点.会话通常还会对服务器性能产生更大的影响,因为服务器必须处理每个会话,而带有cookie的任务则将这项工作分担给每个客户端.

服务器会话更适合大型结果集,因为它们不需要在客户端和服务器的每个请求之间来回发送.

在某些情况下,Session和Cookies都不是一个好答案,URL参数或其他方法是更好的选择.在网络上,我们希望能够在同一网站上启动多个浏览器,并经常单击后退"和前进".使用Cookie或会话来存储应用程序状态可能会导致无法在两个单独的浏览器窗口中执行相同操作的问题.在这种情况下,基于URL参数的状态机制可能更合适.

希望快速概述对您有所帮助.阅读 Session
My rule is:

1) If you can, use a URL paramater to store state, because it provides the most predictable and scalable ''web behavior''
2) ..if that''s not suitable, use a URL-based session, because it provides more predictable web behavior than cookie-sessions
3) ..if that''s not suitable, use a cookie, because it scales easily
4) ..if that''s not suitable, use a cookie based session, because, well.. nothing else worked

A cookie is stored by the client browser and sent back from the client to the server each time it requests a webpage fro the same cookie domain (normally the same server name or domain). A cookie can be set to live a short time, or a very long time (including forever).

A Session is server-side storage, which is generally stored in ram or on-disk on your server. Each time the same client comes back to the server, the server-side session storage is loaded/available. A unique URL paramater or cookie must be used to identify the client, so you can find his server-side session state.

Cookies are easier to scale across multiple web servers, because the client stores and re-produces the cookie each request, regardless of which server they are sent to in a load-balanced situation. Server-affinity load balancing can remedy this to a degree, but has it''s own set of drawbacks. Sessions also usually impact server performance more, because the servers have to handle every session, wheras with cookies this work is offloaded to each client for himself.

Server Sessions are much more suitable for large result sets, as they don''t need to be sent back and forth between the client and server each request.

In some situations, neither Sessions nor Cookies are a good answer, and URL paramaters or other methods are a better choice. In the web, we expect to be able to launch multiple browsers on the same website, and click "back" and "forward" often. Using Cookies or Sessions to store application state can create problems where the same operation can''t be performed in two separate browser windows. In this case a URL paramater based state-mechanism may be more appropriate.

Hope that quick overview helped. Read the wikipedia pages on Session and Cookie for more information.


这篇关于Session和Cookie之间的差异.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆