C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Client Side State Management Using Cookies


Posted Date: 14 Apr 2008    Resource Type: Articles    Category: Web Applications

Posted By: Abhijit Jana       Member Level: Gold
Rating:     Points: 8



Introduction



What is Cookie ?
 A Cookie is small amount of data that is created by web server and store in Client System Either in flat file or memory.
There are two types of cookies
Temporary [ stored in memory]
Persistence [ stored in flat File ]

Use of Cookies:


To identify the user who is viewing the page
To use Remember password facility
store user preference
store encrypted token data


Part of web client and web server to create and use cookies:


Step 1: If user visit first time in the side , user send the request to web page
Step 2 : Web server create corresponding required cookies and send with the response that may be store in client system or memory
Step 3 : After step 2 , for every step client will send the cookies information to the same Web server for viewing any page

Reading and writing cookies


For writing cookies we have to use Response.Cookies and Reading Request.Cookies
E.g
For write

Response.Cookies["lastVisitTime"].Value = DateTime.Now.ToString();
Response.Cookies["lastVisitTime"].Expires = DateTime.Now.AddDays(1);

For Read

if(Request.Cookies["lastVisitTime"] != null)
Response.Write ("Last Visted At : " + Server.HtmlEncode(Request.Cookies["lastVisitTime"].Value);

Limitation of Cookies


Maximum Cookies: We can store maximum 20 Cookies / Sites
Size of Cookies : Maximum size / vookies is 4 KB
To avoid this disadvantage we can use multiple cookies in a single cookies

Response.Cookies["UserDetails"]["firstName"].Value = "Abhijit";
Response.Cookies["UserDetails"]["lastName"].Value = "Jana";


We can also have Domain and Path property to limit the scope of cookies

Summary



Cookies is the best way to store temporary data in client side




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Referencing Controls in Templates after mode changes in Formview
Previous Resource: Implementing TreeView Data Binding with an XML File
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

budget conference call

Contact Us    Privacy Policy    Terms Of Use