ASP .Net, Web Forms and Web Controls
description
Transcript of ASP .Net, Web Forms and Web Controls
![Page 1: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/1.jpg)
ASP .Net, Web Forms and Web Controls
1
OutlineSession Tracking
CookiesSession Tracking with HttpSessionState
![Page 2: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/2.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/3.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/4.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/5.jpg)
5
Defines five radio
buttons
![Page 6: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/6.jpg)
OptionsPage.aspx
6
Request current page, does not cause a postback
![Page 7: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/7.jpg)
7
Define books as a Hashtable, stores key-value
Add values to Hashtable
![Page 8: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/8.jpg)
8
Determines whether the user selected a language
Three hyperlinks are made visible
![Page 9: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/9.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/10.jpg)
10
Displays the recommendations created by the code-behind file
Label displays text recommendations
![Page 11: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/11.jpg)
11
![Page 12: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/12.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/13.jpg)
RecommendationsPage.aspx.cs Program Output
13
![Page 14: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/14.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/15.jpg)
OptionsPage.aspx.cs Program Output
15
![Page 16: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/16.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/17.jpg)
Options.aspx
17
![Page 18: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/18.jpg)
18
![Page 19: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/19.jpg)
19
![Page 20: ASP .Net, Web Forms and Web Controls](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/20.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051517/56814fca550346895dbd8a0c/html5/thumbnails/21.jpg)
Program Output
21