Cookies in Asp.Net
- Usama Liaquat
- Jan 28, 2017
- 2 min read
Cookies is a bit of text that contains information. This information can be read whenever the user visits the site.
Even you can create your own cookie to store some information.
In this example i will show you : How to create and name them a cookie and store some information.

first of all create your project [named 'cookie' ].

and select Empty project. Select Webform to create a Webform Application.

and here create web form by right click to our project select Add > Webforms and name them Default.

When the Webform is created. Open Default.aspx and type the following code in opening and closing <div>.

there are two controls textbox control and button control. Now open up the desgin tab in center of the bottom. and double click on button control.
visual studio automatically generated a method that name is Submit_Click.

now type it a variable like var = cookie and store a new instance of httpcookie("","");
like this:

like.

now i am generated a cookie named Cookie_name and store the value in the cookie
like control.text;
On the second line type it here Response.Cookies.add(variable).to store in the cookie section on the web browser. like this

lets run our program.
type the cookie value and click button, When you click button. Cookie value and name now store in the browser of cookie section. let see where the cookie section is press F12 and go to the application tab like this.

now go to the url you can see your cookie information.

when you refresh page the cookie value store in the textbox type first word of your cookie.
you can see you cookie_value is in your option of textbox.
Want to see video here is the video link.
Comments