Wednesday 19 August 2015

What is Cookie in asp.net

   Cookie is a small amount of memory used by web server within client system.

The purpose is maintaining personal information of client within client system to reduce on server.

Cookie can be classified into 2 types

                       1. In-memory cookie

                       2. Persistant cookie

1. In-Memory Cookie :   The Cookie placed within browse process memory is called in-memory cookie.


  •    It is temporary cookie specific to browser instance. Once browser will be closed, cookie will be erased.
  • Cookie data will be accessible to all the web pages with client request.
  • .Net is providing HttpCookie class for sending cookie or reading cookie.
     Sending Cookie : 

                   HttpCookie obj = new HttpCookie("Name");

                                       obj.value = "100";

                  Response. Appendcookie(obj);

        
     Reading Cookie submitted by client : 

                      HttpCookie obj = null;

                                       obj = Request.Cookie["Name"];

                            if ( obj == null)

                            {
                              // No cookie submitted       
                            }
                            else
                                obj.value ;


2.  Persistant Cookie : 
                                      Cookie placed with in hard disk memory of client system is called persistant cookie. This will be maintained by client system with perticular lifetime.
                             



No comments:

Post a Comment