Last post Dec 07, 2013 09:24 PM by Amit Sheoran
Dec 07, 2013 09:24 PM|Amit Sheoran|LINK
if (Request.Cookies["CookiesName"] !=
Response.Cookies["Cookies"].Expires = DateTime.Now.AddDays(-1);
Response.Redirect("Default.aspx"); //to refresh the page
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.
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.
Cookie's common property:
HttpCookie class has a list of some properties, let us outline them.
Domain: It contains the domain of the cookie.
Expires: It contains the expiration time of the cookie.
HasKeys: It contains True if the cookie has subkeys.
Name: It contains the name of the cookie.
Path: It contains the virtual path to submit with the cookie.
Secure: It contains True if the cookie is to be passed in a secure connection only.
Value: It contains the value of the cookie.
Limitations of Cookies
There are following limitations for 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.
End user can stop accepting cookies by browsers, so it is recommended to check the users’ state and prompt the user to enable cookies.
Sometimes, the end user disables the cookies on browser and sometimes browser has no such feature to accept cookies. In such cases, you need to check the users’ browser at the home page of website and display the appropriate message or redirect
on appropriate page having such message to enable it first. The following code will check whether the users’ browser supports cookies or not. It will also detect if it is disabled too.
protected void Page_Load(object
sender, EventArgs e)
//supports the cookies
//not supports the cookies
//redirect user on specific page
//for this or show messages