December 10, 2013 06:24 by Ben
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 that you created in ASP.NET.
Cookies could be stolen by hackers to gain access to a victim's web account. Even cookies are not software and they cannot be programmed like normal executable applications. Cookies cannot carry viruses and cannot install malware on the host computer. However, they can be used by spyware to track user's browsing activities.
How to create a cookie?
There are many ways to create cookies, I am going to outline some of them below:
HttpCookie userInfo = new HttpCookie("userInfo");
userInfo["UserName"] = "Annathurai";
userInfo["UserColor"] = "Black";
userInfo.Expires.Add(new TimeSpan(0, 1, 0));
Response.Cookies["userName"].Value = "Annathurai";
Response.Cookies["userColor"].Value = "Black";
How to delete cookie?
Now look at the code given below which will delete cookies.
string User_Name = string.Empty;
string User_Color = string.Empty;
User_Name = Request.Cookies["userName"].Value;
User_Color = Request.Cookies["userColor"].Value;
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:
- Domain => Which is used to associate cookies to domain.
- Secure => We can enable secure cookie to set true(HTTPs).
- Value => We can manipulate individual cookie.
- Values => We can manipulate cookies with key/value pair.
- Expires => Which is used to set expire date for the cookies.
Advantages of Cookie:
- Its clear text so user can able to read it.
- We can store user preference information on the client machine.
- Its easy way to maintain.
- Fast accessing.
- Disadvantages of Cookie
- If user clear cookie information we can't get it back.
- No security.
- Each request will have cookie information with page.
How to clear the cookie information?
we can clear cookie information from client machine on cookie folder
To set expires to cookie object
userInfo.Expires = DateTime.Now.AddHours(1);
It will clear the cookie with one hour duration.
Our Special ASP.NET 4.5.1 Hosting Complete Features
- 24/7 Monitoring, We do 24/7 monitoring of your ASP.NET to make sure that we proactively kill any trouble. This helps to ensure maximum uptime and performance.
- Easy-to-use service (1-click installs), ASPHostPortal.com gives you access to all SimpleScripts features, provides easy one-click installation and management of all popular applications.
- Fast and Secure Server, Our powerfull servers are especially optimized and ensure the best ASP.NET 4.5.1 performance. We have best data centers on three continent and unique account isolation for security.
- Daily Backup Service, We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it.