asp .net, web forms and web controls

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

Upload: jeff

Post on 21-Jan-2016

36 views

Category:

Documents


0 download

DESCRIPTION

ASP .Net, Web Forms and Web Controls. Outline Session Tracking Cookies Session 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ASP .Net, Web Forms and Web Controls

ASP .Net, Web Forms and Web Controls

1

OutlineSession Tracking

CookiesSession Tracking with HttpSessionState

Page 2: ASP .Net, Web Forms and Web Controls

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

Page 3: ASP .Net, Web Forms and Web Controls

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

Page 4: ASP .Net, Web Forms and Web Controls

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

Page 5: ASP .Net, Web Forms and Web Controls

5

Defines five radio

buttons

Page 6: ASP .Net, Web Forms and Web Controls

OptionsPage.aspx

6

Request current page, does not cause a postback

Page 7: ASP .Net, Web Forms and Web Controls

7

Define books as a Hashtable, stores key-value

Add values to Hashtable

Page 8: ASP .Net, Web Forms and Web Controls

8

Determines whether the user selected a language

Three hyperlinks are made visible

Page 9: ASP .Net, Web Forms and Web Controls

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

Page 10: ASP .Net, Web Forms and Web Controls

10

Displays the recommendations created by the code-behind file

Label displays text recommendations

Page 11: ASP .Net, Web Forms and Web Controls

11

Page 12: ASP .Net, Web Forms and Web Controls

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

Page 13: ASP .Net, Web Forms and Web Controls

RecommendationsPage.aspx.cs Program Output

13

Page 14: ASP .Net, Web Forms and Web Controls

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

Page 15: ASP .Net, Web Forms and Web Controls

OptionsPage.aspx.cs Program Output

15

Page 16: ASP .Net, Web Forms and Web Controls

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.

Page 17: ASP .Net, Web Forms and Web Controls

Options.aspx

17

Page 18: ASP .Net, Web Forms and Web Controls

18

Page 19: ASP .Net, Web Forms and Web Controls

19

Page 20: ASP .Net, Web Forms and Web Controls

20

Event handler PageInit retrieves session information

Indexing the Session object with key name

Iterates through the Session object

Page 21: ASP .Net, Web Forms and Web Controls

Program Output

21