asp.net, web forms and web controls 1 outline session tracking cookies session tracking with...

21
ASP .Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState

Upload: tyrone-daniels

Post on 13-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

ASP .Net, Web Forms and Web Controls

1

OutlineSession Tracking

CookiesSession Tracking with HttpSessionState

Session Tracking • Personalization

• Tailored to client’s needs• Creates customer loyalty• Requires a Session ID – represents a unique client

• Tradeoff: Privacy protection• Release of vital, possibly private, data

• Tracking achieved by using • Cookies• ASP.NET’s HttpSessionState object• Hidden input form elements and URL tracking

2

Cookies• Cookies

• Text file stored by a Web site on a individual’s computer that allows the site to track the actions of the visitor

• Records sites that the user visits and identifies shopping preferences• Cookies can store name-value pairs • Web Server can never access cookies created outside the domain

associated with that server• Cookie’s Expires property (default is browsing session)

3

OptionsPage.aspx.cs Program Output

4

Server creates a cookie that stores a record of the chosen language, as well as the ISBN number for a book.

When user clicks hyperlink, the cookies previously stored on the client are read and used to form a list of book recommendations

5

Defines five radio

buttons

OptionsPage.aspx

6

Request current page, does not cause a postback

7

Define books as a Hashtable, stores key-value

Add values to Hashtable

8

Determines whether the user selected a language

Three hyperlinks are made visible

9

Returns value corresponding to key contained in language

New cookie object created to store language and ISBN number

Cookie is added to the cookie collection sent as part of HTTP response header

10

Displays the recommendations created by the code-behind file

Label displays text recommendations

11

12

Ensure that there is at least one cookie

Add information in other cookies into list box

Execute if no language was selected

Method to retrieve cookies from the client

RecommendationsPage.aspx.cs Program Output

13

Session Tracking with HttpSessionState• HttpSessionState

• HttpSessionState objects can store any type of objects (not just Strings) as attribute values

• Example modified:• The ASPX file is similar

14

OptionsPage.aspx.cs Program Output

15

Session Tracking with HttpSessionState• Every Web Form includes an HttpSessionState

Object, accessible through property Session of class Page

• Use this property Session to manipulate page’s HttpSessionState object.

16

Properties Description

Count Specifies the number of key-value pairs in the Session object.

IsNewSession Indicates whether this is a new session (i.e., whether the session was created when loading this page).

IsReadOnly Indicates whether the Session object is read-only. Keys Returns a collection containing the Session object’s keys. SessionID Returns the session’s unique ID. Timeout Specifies the maximum number of minutes during which a

session can be inactive (i.e., no requests are made) before the session expires. By default, this property is set to 20 minutes.

Options.aspx

17

18

19

20

Event handler PageInit retrieves session information

Indexing the Session object with key name

Iterates through the Session object

Program Output

21