P1247676908eviYL - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

P1247676908eviYL

Description:

Cookie cannot be used as a virus, and it cannot access your hard drive. Cookies are being used for tracking people's browsing habits, and that makes a ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 10
Provided by: saxserv
Category:

less

Transcript and Presenter's Notes

Title: P1247676908eviYL


1
State Management
2
Problems of HTML
  • Stateless
  • When the page is delivered, the connection
    stopped.
  • State
  • Provides the ability to associate variables
    (information) with a specific user or a specific
    transaction

3
Session
  • A statement that adds or updates a session state
    item
  • Session("EMail") sEmail
  • A statement that retrieves the value of a session
    state item
  • Dim sEmail As String Session("EMail").ToString
  • A statement that removes an item from session
    state
  • Session.Remove("EMail")

4
Cookies
  • Cookie or magic cookie
  • A small chunk of privileged or secret data
  • In the Web context
  • A small amount of data stored by a Web browser

5
Cookies
  • Two ways to create a cookie
  • cookie New HttpCookie(name)
  • cookie New HttpCookie(name, value)
  • Common properties of the HttpCookie class
  • Expires
  • Name

6
Create Cookies
  • Code that creates a session cookie
  • Dim NameCookie As New HttpCookie("UserName",
    sUserName)
  • Syntax to create a new object in VB
  • Dim objName As New className()
  • Code that creates a persistent cookie
  • Dim NameCookie As New HttpCookie("UserName")
  • NameCookie.Value sUserName
  • NameCookie.Expires Now().AddYears(1)

7
A Procedure to Create a Cookie
  • Private Sub AddCookie()
  • Dim NameCookie As New HttpCookie("UserName",
    _
  • txtUserName.Text)
  • NameCookie.Expires Now.AddYears(1)
  • Response.Cookies.Add(NameCookie)
  • End Sub

8
A Procedure to Retrieve the Value of a Cookie
  • Protected Sub Page_Load(ByVal sender As Object, _
  • ByVal e As System.EventArgs) Handles
    Me.Load
  • If Not IsPostBack Then
  • If Request.Cookies("UserName") IsNot
    Nothing Then
  • lblUserName.Text "Welcome back " _
  • Request.Cookies("UserName").Valu
    e _
  • "."
  • End If
  • End If
  • End Sub

9
What about Privacy?
  • Cookie cannot be used as a virus, and it cannot
    access your hard drive
  • Cookies are being used for tracking people's
    browsing habits, and that makes a lot of people
    really uncomfortable.
Write a Comment
User Comments (0)
About PowerShow.com