Understanding Cookies: Storage, Location, and Usage with Active Server Pages, Slides of Fundamentals of E-Commerce

An overview of cookies, their storage locations in different browsers, and the process of setting and sending cookies using active server pages (asp). It covers the format of cookie headers, cookie properties, and writing and reading cookies with asp.

Typology: Slides

2012/2013

Uploaded on 07/29/2013

sheil_34
sheil_34 🇮🇳

4.4

(14)

129 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Server-Side Web Programming
with Active Server Pages
Cookies Overview
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Understanding Cookies: Storage, Location, and Usage with Active Server Pages and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Server-Side Web Programming

with Active Server Pages

Cookies Overview

Introduction

-^ Cookies are small pieces of information stored bythe webserver on the client’s machine. •^ Cookie information is saved in small files createdand saved by the client’s browser. •^ Cookie information is sent back to the webserverthat generated the cookie. •^ Originally developed by Netscape. Now definedby RFC 2109 (“

HTTP State Management Mechanism

-^ Developed as a mechanism to maintain statebetween client requests.

Cookie Viewing Demonstration

Setting Cookies via HTTP (1) A cookie is sent to client

by the webserver

using a one-

line HTTP response header. Set-Cookie: NAME=VALUE;

expires=DATE; domain=DOMAIN_NAME;

path=PATH; secure e.g., Set-Cookie: UserID=234;

domain=valtara.com; path=/;

expires=Monday, 10-Nov-1999 23:59:59Set-Cookie: TestVal=test; domain=valtara.com; path=/test/;expires=Monday, 10-Nov-1999 23:59:

Sending Cookies via HTTP When client navigates to a URL with a matchingcookie, browser sends an HTTP request header: Cookie:Name1=Value1;Name2=Value2;… e.g., if client visits Valtara home page, browsersends this cookie to webserver: Cookie: UserID=1 e.g., if client visits Valtara /test/ directory,browser sends both of these cookies, Cookie: UserID=1Cookie: TestVal=test

Cookies

-^ Cookie management systems are browser-specific. •^ Programming languages like ASP abstract cookiewriting/retrieval so you don’t need to know how theclient is managing their cookies.

Cookie Properties

-^ Expires

: Number of days to persist cookie. Typically use

date+x

days or set to a specific

date with

-^ Domain

: Domain cookie originated from. Only used when you only want cookies sent to aspecific subdomain (e.g., sub1.mydomain.com vs.sub2.mydomain.com). • Path

: Virtual path cookie originated from. Only used when only want cookies sent for pages in aspecific path (e.g., /mypath). Path must matchcase of your webserver.

Cookies Properties

-^ HasKeys:

If cookie is a dictionary cookie, returns TRUE. Otherwise, returns FALSE. • Count:

Count of values in a dictionary cookie.

-^ Secure

: When present, instructs browser to send cookie encrypted to the

Path

only using HTTPS.

Rarely used since you normally want to avoidsensitive information in your cookies.

Writing Cookies in ASP

-^ Writing a single cookie: Response.Cookies("MyCookie") = MyValueResponse.Cookies("DicCookie")("Val1") = "Value1" Setting the Cookie Expiration Response.Cookies("MyCookie").Expires = date + 1Response.Cookies("MyCookie").Expires = #1/1/2000# •^ Setting other cookie attributes: Response.Cookies("MyCookie").Domain = "valtara.com"Response.Cookies("MyCookie").Path = "/test" Response.Cookies("MyCookie").Secure = True

Writing Cookies in ASP

•^ Writing values to a dictionary cookie: Response.Cookies("MyCookie")("1stVal") = 1Response.Cookies("MyCookie")("2ndVal") = 2 •^ Generally you want to use dictionary cookies,even if you have only one value, because youwill probably want to add other values laterand will the multiple name/value pairs.