Cookies and Sessions
What is the Difference between Cookies and Session in ASP.net?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SubashPosted Jul 4, 2016, 6:50 AM
SubashPosted Jul 4, 2016, 6:48 AM
SubashPosted Jul 4, 2016, 6:42 AM
SubashPosted Jul 4, 2016, 6:21 AM
@Munesh SharmaThanks Simple and Easy to understand
Munesh SharmaPosted Jul 4, 2016, 6:18 AM
1. Cookies can store only "string" datatype
2. They are stored at Client side
3. Cookie is non-secure since stored in text format at
client side
4. Cookies may or may not be individual for every
client
5. Due to cookies network traffic will increase.Size
of cookie is limited to 40 and number of cookies to be used
is restricted to 20.
6. Only in few situations we can use cookies because
of no security
7. We can disable cookies
8. Since the value is string there is no security
9. We have persistent and non-persistent cookies
Session
1. Session can store any type of data because the
value is of datatype of "object"
2. These are stored at Server side
3. Session are secure because it is stored in binary
format/encrypted form and it gets decrypted at server
4. Session is independent for every client i.e
individual for every client
5. There is no limitation on size or number of
sessions to be used in an application
6. For all conditions/situations we can use sessions
7. we cannot disable the sessions.Sessions can be used
without cookies also(by disabling cookies)
8. The disadvantage of session is that it is a
burden/overhead on server
9. Sessions are called as Non-Persistent cookies
because its life time can be set manually
Vinay SinghPosted Jul 4, 2016, 5:39 AM
• A cookie can keep all the information in the client's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie.
• Sessions are not reliant on the user allowing a cookie. They work like a token in the browser which allowing access and passing information while the user has opened his browser. The problem in sessions is when you close the browser the session will automatically lost. So, if you had a site requiring a login, this couldn't be saved as a session but it can be saved as a cookie, and the user has to re-login every time they visit.
Praveen SreeramPosted Jul 4, 2016, 5:28 AM
- Client Side
- Server Side
Application variables and session variables could be used in Server Side State management- Sessions are stored in Server's RAM and so are secured.
- You can store any amount of data (depending on your hardware resources of your server. It's not recommended to store huge volumes of course.
Cookies:- There are two types of cookies
- In-memory cookies - These are expired as soon as you close the browser
- Persistant Cookies - There are stored in user's hard disk even if the browser is closed. ex: In facebook / gmail, "Remember me" functionality use this.
- As these are stored in user's hard disk, these are not secured.
- There is a limitation for saving data in each cookie. I think it's 4 MB.
You need to use them based on the requirement and the guidelines.Rajeev PunhaniPosted Jul 4, 2016, 5:19 AM
Hi Subhash,
Bothcookies and session are state management techniques in Asp.net.
If the above solution is helpful then,accept the answer.