Prev | Current Page 157 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"


The cookie information passed between browser and server is delivered via HTTP headers.
The web server will send down to the browser client an HTTP header named Set-Cookie with
the information it wants the browser to persist on the user??™s local machine. The next time the
user visits that site (and only that site), the browser responds with a Cookie HTTP header
containing the locally stored site-specific data, as long as the cookie hasn??™t expired.
ASP.NET provides access to outgoing cookies via the Cookies property of the HttpResponse
class. HttpResponse represents the output of the web form and is reached through the Response
property of the Context object, which is available to server controls via the System.Web.UI.Control
class. The Cookies collection is serialized to a set of string values attached to HTTP headers.
CHAPTER 3 ?–  A SP.NET S TATE MANAGEMENT 91
The following code adds two differently named cookies representing the first and last
name of one of the authors to the Cookies collection:
Response.Cookies["firstname"] = "Dale";
Response.Cookies["lastname"] = "Michalk";
The Cookies collection serialization process generates two Set-Cookie headers, one for
each cookie being sent down to the browser:
Set-Cookie: firstname=Dale; path=/
Set-Cookie: lastname=Michalk; path=/
The HttpRequest class has a Cookies collection that allows the developer to read incoming
cookies in a manner identical to the outgoing collection.


Pages:
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169