How to create Cookies With Example
What is Cookies and how to create:
In computing, a cookie is a small string of text stored on a
user’s computer by a web browser. A cookie consists of one or more name-value
pairs containing bits of information such as user preferences, shopping cart
contents the identifier for a server-based session, or other data used by
websites.
It is sent as an HTTP header by a web server to a web client
(usually a browser) and them sent back unchanged by client each time it
accesses that server . A cookie can be used for authenticating, session
tracking (state maintenance), and maintaining specific information about users,
such as site preferences or the contents of their electronic shopping carts.
Example of asp.net cookies:
To write a cookie by creating an instance of the HTTP cookie object.
1. Create an object of type HTTP cookies and assign it a name.
2. Assign values of cookies, by set cookies property.
3. Add the cookies to cookies collection.
Example:
http cookie ck1,ck2;
ck1=new http cookies("name",Textbox1.text);
responce,cookies.add(ck1);
}
Creating cookies in asp.net :
HttpCookie myCookie = Request.Cookies["myCookie"];if (myCookie == null)
{
}
if (!string.IsNullOrEmpty(myCookie.Values["userid"]))
{
string userId = myCookie.Values["userid"].ToString();
}
Cookies are known by many other names,
1. HTTP Cookie,2. Web Cookie,
3. Browser Cookie,
4. Session Cookie, etc.
Clint site storage ,Cookies are one of several ways to store data about web site visitors during the time when web server and browser are not connected. Common use of cookies is to remember users between visits. Practically, cookie is a small text file sent by web server and saved by web browser on client machine.
Disadvantage of cookies :
Size of cookies is limited to 4096 bytes.Total 20 cookies can be used on a single website;
if you exceed this browser will delete older cookies.
User handled ,End user can stop accepting cookies by browsers,Less security .
Cookies are used for shopping basket or shopping cart at Amazon.com, whereby the cookies store any addition or deletion by the users for the terms they wise to purchase.
Other Asp.net related Post:
Asp.net
page Directives
Asp.net Label control
Textbox Asp.net control
ImageButton control
Asp.net Button control.
Check box in ASP.NET GridView
Asp.net checkbox list Example
Asp.net Imagebutton control example
Ckeck box list example-using-javascript.
Print pdf file in asp.net by C sharp
SQL Server questions for interview
Find datetime difference in asp.net by C#
Add rows in GridView dynamic with Textbox
Asp.net Watermark Text on uploaded Image
Asp.net NullReferenceException and how fix it
State Management and type of State Management
Cookies,how to make Cookies in asp.net with C#.
Jquery Change div background on mouseover in asp.net
In asp.net by jquery change div text color on mouseover
Upload multiple by one asp.net fileupload control using jQuery
Adding Dynamic Rows in ASP.Net GridView Control with Textbox
In Asp.net Difference between ""(empty string) and String.Empty
Validation checkbox control using JavaScript
Validate ASP.Net RadioButtonList using JavaScript Example
Asp.net Label control
Textbox Asp.net control
ImageButton control
Asp.net Button control.
Check box in ASP.NET GridView
Asp.net checkbox list Example
Asp.net Imagebutton control example
Ckeck box list example-using-javascript.
Print pdf file in asp.net by C sharp
SQL Server questions for interview
Find datetime difference in asp.net by C#
Add rows in GridView dynamic with Textbox
Asp.net Watermark Text on uploaded Image
Asp.net NullReferenceException and how fix it
State Management and type of State Management
Cookies,how to make Cookies in asp.net with C#.
Jquery Change div background on mouseover in asp.net
In asp.net by jquery change div text color on mouseover
Upload multiple by one asp.net fileupload control using jQuery
Adding Dynamic Rows in ASP.Net GridView Control with Textbox
In Asp.net Difference between ""(empty string) and String.Empty
Validation checkbox control using JavaScript
Validate ASP.Net RadioButtonList using JavaScript Example