What is cookie? Advantages and disadvantages of cookies

Introduction: In previous articles i explained the Difference between Delete and Truncate in sql server
 and  Difference between Response.Redirect and Server.Transfer in asp.net and Difference between DataSet and DataTable in asp.net and 15 main Difference between DataSet and DataReader in asp.net and 20 main differences between Stored procedures and Functions in Sql Server  and
What is Page.IsValid and Page.Validate in Asp.net ? are most important interview questions.Similarly cookie is also one of the most important interview question asked in interview to freshers.Let's understand.

What is cookie?
A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions.

Some facts about Cookie

Here are a few facts to know about cookies:
  1. ·         Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose.
  2. ·         Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome) will not be accessed by another browser(Internet Explorer/Firefox).
  3. ·         Most of the browsers store cookies in text files in clear text. So it’s not secure at all and no sensitive information should be stored in cookies.
  4. ·         Most of the browsers have restrictions on the length of the text stored in cookies. It is 4096(4kb) in general but could vary from browser to browser.
  5. ·         Some browsers limit the number of cookies stored by each domain(20 cookies). If the limit is exceeded, the new cookies will replace the old cookies.
  6. ·         Cookies can be disabled by the user using the browser properties. So unless you have control over the cookie settings of the users (for e.g. intranet application), cookies should not be used.
  7. ·         Cookie names are case-sensitive. E.g. UserName is different than username.
Advantages of using cookies
  1. Here are some of the advantages of using cookies to store session state.
  2. ·         Cookies are simple to use and implement.
  3. ·         Occupies less memory, do not require any server resources and are stored on the user's computer so no extra burden on server.
  4. ·         We can configure cookies to expire when the browser session ends (session cookies) or they can exist for a specified length of time on the client’s computer (persistent cookies). 
  5. ·         Cookies persist a much longer period of time than Session state.

Disadvantages of using cookies

Here are some of the disadvantages:
  1. ·         As mentioned previously, cookies are not secure as they are stored in clear text they may pose a possible security risk as anyone can open and tamper with cookies. You can manually encrypt and decrypt cookies, but it requires extra coding and can affect application performance because of the time that is required for encryption and decryption
  2. ·         Several limitations exist on the size of the cookie text(4kb in general), number of cookies(20 per site in general), etc.
  3. ·         User has the option of disabling cookies on his computer from browser’s setting .
  4. ·         Cookies will not work if the security level is set to high in the browser.
  5. ·         Users can delete a cookies.
  6. ·         Users browser can refuse cookies,so your code has to anticipate that possibility.
  7. ·         Complex type of data not allowed (e.g. dataset etc). It allows only plain text (i.e. cookie allows only string content)
Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

5 comments

Click here for comments
Anonymous
March 16, 2013 ×

nice writing ....thanks keep writing

Reply
avatar
admin
Anonymous
August 24, 2013 ×

Nice....

Reply
avatar
admin
August 24, 2013 ×

thanks for your appreciation..

Reply
avatar
admin
October 01, 2013 ×

Lalit ji nice work

Reply
avatar
admin
October 01, 2013 ×

Thanks Viresh..i am glad you like my work..stay connected and keep reading :)

Reply
avatar
admin

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. Out Of Topic Show Conversion CodeHide Conversion Code Show EmoticonHide Emoticon

Thanks for your comment