freshers/Experienced Dotnet jobs

12/07/2011

What is a cookie ?

Cookie is a piece of information stored in the client computer/Browser which is limited to 4k in size.

Advatanges:-
  1.  very simple to implement
  2. Browser automatically arranges cookies stored for multiple sites
Disadvantages:-
  1. It stores cookie data in simple text format,so its not secure.
  2. cookie size limited to 4 kb
  3. No. of cookies stored by browser are limited to 20.some allow 300,when a new cookie comes old one will be discarded,


There are 2 types of cookies
  • Non-persistent(Temporary) cookies
  • Persistent(Permanent) cookies



      Non-persistent :- Also called as session cookies or In memory cookies.These are destroyed when you close your browser.

      Persistent :-  These are saved as a text file in file system of a clients computer ,Generally under TEMPORARY INTERNET FILES folder .

      cookie Expires property must be set to create persistent cookie.
      ex:- Remember me option.

      Example to create persistent cookie

      //create a cookie object

      httpcookie cookie1= new httpcookie("userdetails");

      //setting values to inside it

      cookie1["username"]="naga";
      cookie["usercolor"]="green";
      cookie["expire"]=" 5 days";

      //Adding expire time of cookies

      cookie1.expires=DateTime.Now.ADD(5);
      response.cookies.Add(cookie1);



      No comments:

      Post a Comment