0% found this document useful (0 votes)
27 views

Type of Cookies?: Timespan

Cookies are small pieces of information stored on a user's computer that contain information like usernames, passwords, and preferences. There are two types of cookies: persistent cookies that don't expire and non-persistent cookies that do expire. Cookies can be created in ASP.NET using the Response object or HttpCookie class by adding name-value pairs. Cookies values are retrieved from requests using the Request object or accessing cookies directly. Cookies are commonly used to store user preferences but also have disadvantages like lack of security if cleared from the user's computer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Type of Cookies?: Timespan

Cookies are small pieces of information stored on a user's computer that contain information like usernames, passwords, and preferences. There are two types of cookies: persistent cookies that don't expire and non-persistent cookies that do expire. Cookies can be created in ASP.NET using the Response object or HttpCookie class by adding name-value pairs. Cookies values are retrieved from requests using the Request object or accessing cookies directly. Cookies are commonly used to store user preferences but also have disadvantages like lack of security if cleared from the user's computer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Cookies is a small piece of information stored on the client machine.

This file is located on


client machines "C:\Document and Settings\Currently_Login user\Cookie" path. Its is used
to store user preference information like Username, Password,City and PhoneNo etc on
client machines. We need to import namespace called Systen.Web.HttpCookie before we
use cookie.

Type of Cookies?

1. Persist Cookie - A cookie has not have expired time Which is called as Persist Cookie

2. Non-Persist Cookie - A cookie has expired time Which is called as Non-Persist Cookie

How to create a cookie?

Its really easy to create a cookie in the Asp.Net with help of Response object or HttpCookie

Example 1:

HttpCookie userInfo = new


HttpCookie("userInfo"); userInfo["UserName"] =
"Annathurai"; userInfo["UserColor"] = "Black";
userInfo.Expires.Add(new TimeSpan(0, 1, 0));
Response.Cookies.Add(userInfo);

Example 2:

Response.Cookies["userName"].Value = "Annathurai";
Response.Cookies["userColor"].Value = "Black";

How to retrieve from cookie?

Its easy way to retrieve cookie value form cookes by help of Request object.

Example 1:

string User_Name = string.Empty;


string User_Color = string.Empty;
User_Name = Request.Cookies["userName"].Value;
User_Color = Request.Cookies["userColor"].Value;

Example 2:

string User_name = string.Empty;


string User_color = string.Empty;
HttpCookie reqCookies = Request.Cookies["userInfo"];
if (reqCookies != null)
{
User_name = reqCookies["UserName"].ToString();
User_color = reqCookies["UserColor"].ToString();
}

When we make request from client to web server , the web server process the request and
give the lot of information with big pockets which will have Header information, Metadata,
cookies etc., Then repose object can do all the things with browser.

Cookie's common property:

1. Domain => Which is used to associate cookies to domain.

2. Secure => We can enable secure cookie to set true(HTTPs).

3. Value => We can manipulate individual cookie.

4. Values => We can manipulate cookies with key/value pair.

5. Expires => Which is used to set expire date for the cookies.

Advantages of Cookie:

1. Its clear text so user can able to read it.

2. We can store user preference information on the client machine.

3. Its easy way to maintain.

4. Fast accessing.

Disadvantages of Cookie

1. If user clear cookie information we can't get it back.

2. No security.

3. Each request will have cookie information with page.

How to clear the cookie information?

1. we can clear cookie information from client machine on cookie folder

2. To set expires to cookie object


userInfo.Expires = DateTime.Now.AddHours(1); It
will clear the cookie with one hour duration.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy