210 likes | 440 Views
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
E N D
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 • Release of vital, possibly private, data • Tracking achieved by using • Cookies • ASP.NET’s HttpSessionState object • Hidden input form elements and URL tracking
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)
OptionsPage.aspx.cs Program Output 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
Defines five radio buttons Label Web control
Request current page, does not cause a postback OptionsPage.aspx
Define books as a Hashtable, stores key-value Add values to Hashtable
Three hyperlinks are made visible Determines whether the user selected a language
Cookie is added to the cookie collection sent as part of HTTP response header Returns value corresponding to key contained in language New cookie object created to store language and ISBN number
Label displays text recommendations Displays the recommendations created by the code-behind file
Method to retrieve cookies from the client Ensure that there is at least one cookie Add information in other cookies into list box Execute if no language was selected
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
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.
Indexing the Session object with key name Event handler PageInit retrieves session information Iterates through the Session object