ASP: Course 2 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

ASP: Course 2

Description:

From Prof. Server Pages (WROX) p. 83. Client. Response. Request ... 'From Wrox Prof ASP Book pg. 109. dim item. dim itemkey. for each item in request.cookies ... – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 16
Provided by: valt8
Category:
Tags: asp | course | wrox

less

Transcript and Presenter's Notes

Title: ASP: Course 2


1
ASP Course 2
  • An Introduction to Server-side Scripting
    Continued...

2
ASP References
  • ASP
  • http//www.aspalliance.com
  • http//www.activeserverpages.com
  • http//www.15seconds.com
  • http//www.asphole.com
  • VBScript
  • http//msdn.microsoft.com/scripting/vbscript/doc/v
    bstoc.htm

3
Overview
Client
Response
Server Object
Application Object
Request
Session Object
ObjectContext
From Prof. Server Pages (WROX) p. 83
4
Response Object
  • .Write( ) is used to send text back to the
    client. If the text contains markup information
    (Elements) those are sent and interpreted by the
    browser. Compose strings using the cStr() and
    vbScript Commands.
  • The operator by alone equivalent to
    response.write() lt var gt
  • .Redirect() sends the user to another page. Must
    use .buffer/.flush OR use before ltHTMLgt element.
    Can be used in combination with Browser
    Capabilities Component to direct users to a
    different page.
  • .Clear, .Buffer, .Flush manages how the client
    receives the stream (default is line by line,
    buffered is at end of page or on .Flush.)
  • .Expires or .ExpiresAbsolute properties sets how
    long the browser should cache the page, for most
    ASP pages this should be very small.
  • .AppendToLog() is very useful for recording
    things to the log.
  • The cookies() collection is used to write cookies
    TO the browser.

5
Request Object
  • .Cookies() collection is the cookies fetched from
    the client.
  • .ServerVariables() collection allows the
    programmer to get at environment variables and
    HTTP header information.
  • The Request object contains the information from
    Forms and CGI style queries (from last time).
  • Two Collections
  • .QueryString() for command line parameters
    (?A1v1A2v2) and GET action calls.
  • Form() for POST action calls.
  • BOTH may be used. In fact using both is the best
    and trickiest trick of all. (More about this next
    time!)

6
Request Object and Forms
  • The request objects two collections QueryString()
    and Forms() "front" for the command line
    parameters and STDIN data (from CGI) giving ASP
    programmers a leg up on coping with forms.
  • (ltform action'get' gt) The QueryString()
    collection parses
  • ?arg1v1arg2v2
  • v1 request.QueryString("arg1") , v2
    request.QueryString("arg2")
  • (ltform action'post' gt) The forms collection
    parses the STDIN stream (in the http header) into
    control name, value pairs
  • ltinput type'text' name'txtX'gt
  • v1request.forms("txtX")

7
ASP and Forms
For forms whose action property is 'GET' the form
elements are sent as parameters after the ?
Separated by For forms whose action property
is 'POST' the form elements are sent as part of
the message header to the server.
ltform method'___' action'http//myServer/xyz.asp
gt lt/formgt
1
2
Xyz.ASP
myServer
Explicit Parameters or GET form fields --gt
Request.QueryString()
Submit
http//myServer/xyz.asp?Arg1XArg2Y
Page on Client
3
Response Returned as HTML to Caller
8
Application Object
  • Object contains two important events OnStart()
    events launch with the first invocation of the
    page. OnEnd() events occur during an orderly
    shutdown of webserver. These events can be used
    to create a single instance of an object to be
    used across all sessions (e.g., some business
    logic components or a helper object like a
    discussion web engine)
  • Can provide coordination across all instances of
    a page by use of application collections contents
    and staticobjects, the semaphore methods lock and
    unlock being used to control access to the
    critical sections.
  • Application.Lock 'Prevent other
    sessions from accessing the contents collection
  • Application("myAppVar") 37 'set a value
  • Application.Unlock 'Clear locks

9
Session Object
  • A session is a series of visits by the same
    person to an ASP application in a defined time
    period (default timeout is 30 minutes).
  • A session starts when the user hits a page with
    sessions enabled for the first time (i.e., the
    global.asa file contains the session_onstart()
    event or when the session object is referenced).
  • A session ends when either the abandon method is
    called or when no response from the client occurs
    within the timeout period thus firing the
    session_onend() event.
  • Like the application object, the collections
    contents and staticobjects are used to reference
    variables and objects created in the scope of the
    session.
  • Sessions depend on cookies! Test for browser
    having cookies enabled by sending and receiving a
    cookie.

10
Server Object
  • The .CreateObject() function is most commonly
    used method. It is used to create instances of
    createable objects such as
  • Filesystem (Represents files and file operations)
  • TextStream (used for i/o to files)
  • ADODB (the most common type of database
    connection and recordset library)
  • Browser Capabilities Component

11
ObjectContext Object
  • Used for making transaction based applications
    using Microsoft Transaction Server (IIS 4 runs
    on top of it!)
  • It provides the handle to the specific
    transaction objects and its methods control the
    successful completion of the transactions
    themselves (or not as the case may be.)
  • This allows building web apps that can cooperate
    in n-Phase commitment following the ACID (Atomic,
    Consistent, Isolated, and Durable) rules.
  • The typical example would be pages that allow
    people to do web banking or stock trading.

12
ASP and Cookies
Client Browser
1
Xyz.ASP
myServer
Response.Cookies() sent to browser
Request.Cookies() gets them back
2
13
Sending Cookies.
  • A cookie is a small piece of information that is
    sent back with the response page that contains
    programmer defined strings.
  • In practice any type of information can be sent
    once it is converted to string with the cStr().
  • Cookies can contain arrays of data. The elements
    are called Keys. (More about this on the Request
    object.)
  • The properties
  • .Expires (For cookies that are of limited
    duration)
  • .Domain (So that the cookie is specific to a
    site)
  • .Path (rarely used, specifies a particular
    location on a site)
  • .Secure (Specifies that the cookie should be
    transmitted using https//)
  • Cookies are good. Some people are misinformed
    about cookies and their dangers. ASP Applications
    (using sessions) require cookies.

14
Small Cookies Example
'This sends a cookie with a single value to the
client ' which expires 5/2/2023. Response.cookies
("mySiteCookie") "Moo Cows are
Fun" Response.cookies("mySiteCookie").expires
5/2/2023 Response.cookies("mySiteCookie").domain
'/www.moo.cows/'
15
Getting Cookies from the Client
'Use for each to iterate cookies collection 'From
Wrox Prof ASP Book pg. 109 dim item dim
itemkey for each item in request.cookies if
request.cookies(item).HasKeys then for each
itemkey in request.cookies(item) ...
request.cookies(item)(itemkey) next else ...
request.cookies(item) end if next 'Get the
cookie we sent several slides ago item
request.cookie("mySiteCookie")
Write a Comment
User Comments (0)
About PowerShow.com