Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i am a new developer to .net
Posted

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
 
Share this answer
 
Comments
panduu 29-Jul-12 0:48am    
Thank u for giving the differece exactly
Mohamed Mitwalli 29-Jul-12 2:09am    
your welcome :)
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.
 
Share this answer
 
Comments
panduu 29-Jul-12 0:48am    
Thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900