ASP .Net, Web Forms and Web Controls - PowerPoint

Document Sample
ASP .Net, Web Forms and Web Controls - PowerPoint Powered By Docstoc
					                                                           1
     ASP .Net, Web Forms and Web
                Controls
Outline
          Session Tracking
                  Cookies
                  Session Tracking with HttpSessionState
                                                          2

                    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
   – .NET’s HttpSessionState object
   – Hidden input form elements and URL tracking
                                                                     3

                           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)
                          4




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
                               5




Label Web control




                    Defines five
                      radio
                     buttons
                            6



    OptionsPage.aspx




Request current page,
does not cause a postback
                               7




Define books as a Hashtable,
stores key-value




   Add values to
   Hashtable
                       8




Three hyperlinks are
made visible



Determines whether
the user selected a
language
                                       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




Label displays text recommendations


      Displays the recommendations created
      by the code-behind file
11
                            12


 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
              13



RecommendationsP
age.aspx.cs
Program Output
                                                                  14
         22.6.2 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
              15



OptionsPage.aspx
.cs
Program Output
                                                                                16
              22.6.2 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.

Properties       Description
Count        Specifies the number of key  -value pairs in theSession
             object.
IsNewSession Indicates whether this is a new session (i.e., whether the
             session was created when loading this page).
IsReadOnly   Indicates whether theSession 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.
               17

Options.aspx
18
19
                                                       20




                       Event handler PageInit
                       retrieves session information




                           Indexing the Session
                           object with key name




Iterates through the
Session object
                 21




Program Output