Best Cloud ASP.NET Hosting :: Introduction Cookies in ASP.NET

BestCloudHostingASP.NET | Best and Affordable ASP.NET Hosting. Hello guys today I will explain Cookies in ASP.NET.

What’s Cookies ?

ASPNET-COOKIE_230x221A cookie is a piece of information in the form of a very small text file placed on an internet user’s hard drive. It is generated by a web page server that is basically the computer that operates a web site. The user can also change the cookie before the browser sends it to you. So never store a password, username, email, pan number in cookies. We can declare at least 300 cookies per website and at least 4096 bytes per cookie.

Now the question is, how to declare a Cookie.

1st way

 2nd way

3rd way

We can write multiple values in each cookie.

How we access cookies

The following describes how to access cookies.
For 1st way and 2nd way we use:

 And the 3rd way for multiple values in a single cookie:

 Now how to Delete a Cookie

Click to Claim

Just provide a negative value for the time you add when declaring a Cookie.
I will describe with code:
First we create a page called CreateCookie.aspx as in the following:


 Now we access cookies on another page called ResultCookie.aspx as in the following:


 Happy Coding 🙂

Rate this post