What are cookies? Using Cookies in ASP.NET
This article tells about cookies and how to write and read cookies in ASP.NET web application.
Cookies are used to store user specific information in form of text strings. When a user visits particular website some user specific information gets stored and this information can be retrieved later when the same website gets visited from same machine and can be sent to server. Cookies are associated with websites instead of individual pages.
Web developers can use cookies to store user preference and renders the customized page on next visit according to user's interest. There are browser imposed limitations regarding size of cookies and number of cookies per website which can be stored.
In ASP.NET cookies can be created using class HttpCookie in System.Web namespace.
Cookies are added to the Cookies collection of response object, the object which is responsible for keeping information to be rendered to browser. Example for writing and reading cookie
Create an instance of HttpCookie
Dim mycookie as new HttpCookie("userid")
Set parameters like value and expires
mycookie.Value = "1"
mycookie.Expires = DateTime.Now.AddMonths(1)
Add to the Cookies collection of response object
Response.Cookies.Add(mycookie)
We can do same thing by directly setting values for Response.Cookies collection
Response.Cookies ("userid").value = "1"
Response.Cookies ("userid").Expires = DateTime.Now.AddMonths(1)
The above code creates cookie and store it in user's drive for one month. The following code is used to retrieve a cookie later.
Request object is used to send cookies information along with the request for page to server.
If Not Requet.Cookies("userid") Is Nothing Then
Dim a As String
a= Not Requet.Cookies("userid")
End If
Here first we are checking whether cookie exists or not because it can be deleted by user. Cookies won't work if user has disabled cookies in browser settings.
Happy Coding.
-
Simple Security and Privacy Enhancements for the Casual Web Surfer Using Firefox
| By atomMan | in Software
We all know what cookies are, but what about web bugs and LSO's? Most of us know our web usage can be tracked, but ...
-
Creating a Customized Training Module:Communication with Customers
| By mayur | in Marketing & Advertising
Communication is an integral part of one’s existence today. The utmost necessity of learning the art of communica...
-
Google Chrome: Is It The Best Web Browser?
| By midnightauthor | in General
Google - the search giant - has entered the competition for browsers by releasing the Chrome. Is its browser any go...
-
Build A Free Ecommerce Store Front In Less Than An Hour | By AaronMeagher | in Web Development
Are you looking to start selling online and want a quick and easy solution for your ecommerce storefront? While yo...
-
Black Hat SEO Techniques | By ChandraK | in Web Development
Black hat SEO is a technique that is used to get higher ranking for the website in a base manner. Black hat SEO is ...
-
White Hat SEO Techniques | By ChandraK | in Web Development
White hat SEO is a method that follows all the required webmaster guidelines in effective building of the website. ...
-
Create a panoramic image slideshow in Dreamweaver | By extendstudio | in Web Development
In this tutorial we will make a moving panorama slideshow using Creative DW ImageshowPro and Dreamweaver. We will c...
-
Google Development and Google API Topics | By OGolden | in Web Development
Abundant information is available on Google Data API topics....
-
Using remote desktop in windows XP | By rajeshchoudhary | in Computers
if you want to connect to a machine remotly using Remote Desktop Connection, remote Desktop in target machine needs...
-
setting password wisely for your accounts | By rajeshchoudhary | in Computers
Incidents of information phishing and hacking are happening every now and then. One fine day morning you wake up to...
-
Web.config –configuration file for ASP.NET web application. | By rajeshchoudhary | in Web Development
This article tells what web.config file is, how to write this and how this file is used by run time to apply settin...
-
LAMP-Open Source Solution Stack for web develpoment | By rajeshchoudhary | in Web Development
This article tells about LAMP solution stack which is being used to develop and deploy complete website....
-
php.ini –configuration file for PHP | By rajeshchoudhary | in Web Development
This article tells about PHP’s configuration file php.ini and how to write your own php.ini file to apply custom ...








No comments yet.