Week 8: INTRINSIC ASP OBJECT - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Week 8: INTRINSIC ASP OBJECT

Description:

The first person request a file from your application causes ASP to find the ... The server performs the same steps whether or not the global.asa file exists. ... – PowerPoint PPT presentation

Number of Views:172
Avg rating:3.0/5.0
Slides: 24
Provided by: marily261
Category:
Tags: asp | intrinsic | object | var | week

less

Transcript and Presenter's Notes

Title: Week 8: INTRINSIC ASP OBJECT


1
Week 8 INTRINSIC ASP OBJECT
  • 1.1  Introduction
  • Basically, ASP has seven objects, called
    intrinsic objects are
  • Response Object Used to send info. To client
  • Request Object Used to retrieve info. Included
    with the request from the client
  • Server Object Used communicate with the server
  • Application Object Used to store (cache) info.
    About your application
  • Session Object Used to cache info. about a
    specific browser instance (which usually, but not
    always, corresponds to a single user)
  • ObjectContext Object Used to initiate and
    control transactions and create new objects
    through Microsoft Transaction Server (MTS)
  • ASPError Object Used to obtain info. about
    errors that occur while the the ASP engine
    processes a script.

2
Week 8 INTRINSIC ASP OBJECT
  • The Response Object (Cont..)
  • Used to send output to the client
  • This includes sending info. directly to the
    browser, redirecting the browser to another URL
    and setting cookie values.
  • The most often used methods of Response object
    are the write method and the redirect method.
  • Other methods are AddHeader, AppendToLog,
    BinaryWrite, Clear, End, Flush.
  • The Write method sends a string back to the
    calling client, to be written the browser that
    the calling client used to open the Internet
    conversation.

3
Week 8 INTRINSIC ASP OBJECT
  • The Response Object (Cont..)
  • Example 1
  • Response.Write(Hello World)
  • Example 2
  • Response.Write("ltBgt" "This is my second ASP"
    "lt/Bgt" "ltBRgt")
  • Example 3
  • var myString Inilah script saya
  • Response.Write(myScript)
  • Example 4
  • var now new Date()
  • Response.Write(now)

4
Week 8 INTRINSIC ASP OBJECT
  • The Request Object
  • The Request Object retrieves the values that the
    client browser passed to the server during an
    HTTP request.
  • This includes parameters, passed from an HTML
    form using either the
  • POST method or the GET method, cookies and
    client certificates.
  • The request object also gives access to binary
    data sent to the server,
  • such as file uploads.
  • Most of the Request object function is to
    retrieve query data from a
  • calling client using the Form, Cookies
    QueryString collection.

5
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • The Request object contains five different
    collections of information
  • ClientCertificates contains security
    information
  • Cookies contains cookie values sent by the
    browser
  • Form contains information the user enters into
    input controls and information your application
    has stored in form variables
  • QueryString Contains information sent with the
    URL
  • ServerVariables contains information that the
    server automatically parses for every request.

6
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • Some examples of ServerVariables
  • Example 1
  • Response.Write(Request.ServerVariables("REMOTE_AD
    DR"))
  • Example 2
  • Response.Write(Request.ServerVariables("HTTP_USER
    _AGENT"))
  • Example 3
  • Response.Write(Request.ServerVariables("SERVER_PO
    RT"))
  • Example 4
  • Response.Write(Request.ServerVariables("SERVER_NA
    ME"))
  • Example 5
  • Response.Write(Request.ServerVariables("SERVER_PR
    OTOCOL"))
  • Example 6
  • Response.Write(Request.ServerVariables("SERVER_PO
    RT_SECURE"))
  • Example 7
  • Response.Write(Request.ServerVariables("SERVER_SO
    FTWARE"))

7
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • The Request.QueryString Collection is used for
    passing data between the client and the server
    through the QueryString collection.
  • QueryString data is passed in the URL along with
    the request.
  •  
  • For Example, the URL shown below with 4
    parameters
  • http//localhost/learn/query_string.asp?8Azizian
    Sapawi10AliSeman100azlanAbdAziz

8
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • Example, how to pass QueryString (File 1)

lt _at_LanguageJavaScript gt   lthtmlgt ltbodygt lta
href"query_string.asp?ShowQueryStringFalse8Azi
zianSapawi 10AliSeman100azlanAbdAziz"gt
show employeeslt/agt lt/bodygt lt/htmlgt
9
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • Example, how retrieve QueryString Data (file 2)

lt _at_LanguageJavaScript gt lthtmlgt ltbodygt lt var
field, content if (Request.QueryString("ShowQuery
String") "True" )   for (var counter 1
counter lt Request.QueryString.count
counter) field String(Request.QueryStrin
g.key(counter)) content String(Request.QueryS
tring.item(field)) Response.Write(field " "
content "ltbrgt") else Response.Write(
"this link won't show any values")
gt lt/bodygt lt/htmlgt
10
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • The important thing to know are the following
  • You separate the query string from the URL with a
    question mark
  • You separate names (key) from values with an
    equals sign
  • You separate key-value pairs from each other with
    ampersands
  • URL data cannot contain spaces you must replace
    spaces with plus signs
  • The Request object decodes the data for you
  •  

11
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • Working with The Resquest.Form
  • HTML form can be used when we are going to submit
    some data to through an ASP.
  • When a browser submits form data using the post
    Method, the ASP engine parses the raw HTTP from
    data and stores it in the Request.Form
    collection.
  • The form collection, like other ASP collection,
    stores data by key.
  • If a key has more than one value, the values are
    stored in indexed form.
  • The Request.Form collection has a default Item
    method.

12
Week 8 INTRINSIC ASP OBJECT
  • The Request Object (Cont..)
  • Example
  •  
  • ltform action"test1.asp" method"post"gt
  • ltinput type"text" name"fname"gtltbrgtltbrgt
  • ltinput type"submit" value"submit"gt
  • lt/formgt
  •  
  • lt
  •  
  • if (Request.Form("fname")!"")
  • Response.Write(Request.Form("fname"))
  •  
  • gt

13
Week 8 INTRINSIC ASP OBJECT
  • The Server Object
  • Gives high-level access to the server itself.
  • The Server object is used to access properties
    and methods on the server.
  • Using its properties and methods, we can create
    objects, execute code in other ASP files,
    translate virtual paths to physical paths, and
    perform server-side redirects.
  • The most frequently used methods and properties
    is the one that creates an instance of an ActiveX
    component (ADO), Server.CreateObject.
  • Other methods apply URL or HTML encoding to
    strings, map virtual paths to physical paths, and
    set the timeout period for a script.

14
Week 8 INTRINSIC ASP OBJECT
  • The Server Object (Cont..)
  • Using The Server.CreateObject( ) Method to make a
    connection
  • One of the most powerful object method in ASP
  • To create a connection with server, we can use
    the CreateObject() function
  • CreateObject() takes one parameter, a string
    indicating the object to create.
  • The string is the object library name and a
    period followed by the object within the object
    library that you want to create.
  • The name for the ADO Object Library is ADODB.

15
Week 8 INTRINSIC ASP OBJECT
  • The Server Object (Cont..)
  • The following code create a connection object
  • var Conn
  • Conn Server.CreateObject (ADODB.Connection)
  •  
  • In order to have a viable Connection object and
    live link to a datasource, we use the Open
    Method
  • Conn.Open()
  • We use the Close Method to disconnect to server
    and connection between the object and the
    datasource.
  • Conn.Close()

16
Week 8 INTRINSIC ASP OBJECT
  • The Server Object (Cont..)
  • Creating Recordset Object using the
    CreateObject() Method.
  • Recordset is a distinct object within the ADO
    object library.
  • The following code shows how to create recordset
    and assign to a variable
  • rs Server.Create.Object(ADODB.Recordset)
  • Use Open() Method to make connection active like
  • var Conn
  • Conn Server.CreateObject (ADODB.Connection)
  • rs.Server.CreateObject(ADODB.Recordset)
  • sql SELECT FROM table
  • rs.Open(sql, Conn)

17
Week 8 INTRINSIC ASP OBJECT
  • The Server Object (Cont..)
  • Using The Server.MapPath Method
  • The MapPath method can convert to a relative
    orvirtual path that is the name of the file or
    folder to the actual physical path where the file
    or folder would be stored on the servers hard
    disk.
  • The syntax of the MapPath method is as follow
  • Server.MapPath(path)
  • Where path specifies the relative or virtual path
    whose location you wish to determine.
  • If the path starts with a backward (/) slash, it
    is interpreted as a virtual path and the mapping
    begins at the servers root.

18
Week 8 INTRINSIC ASP OBJECT
  • The Server Object (Cont..)
  • Example
  • Response.Write(Server.MapPath(/default.asp)
  • The output would be c\inetpub\wwwroot\default.a
    sp
  • If the path does not begin with a slash is
    interpreted as being relative to the folder where
    the current ASP is stored.
  • Example
  • Response.Write(ServerMapPath(default.asp)
  • The output would be c\asp\default.asp

19
Week 8 INTRINSIC ASP OBJECT
  • The Session Object
  • One of the most advanced object in ASP.
  • A session begins when a browser instance requests
    a page in your application, and ends when you
    abandon the session via code (when the session
    times out or if the browser refuses the session
    cookie or etc)
  • When a session has requested, the server
    immediately redirects the user to a file called
    global.asa .
  • The server generates a cookie header, then runs
    the code (if any) in the Session_OnStart event in
    the global.asa.

20
Week 8 INTRINSIC ASP OBJECT
  • The Session Object (Cont..)
  • The global.asa file
  • The global.asa file can be found in the root
    directory on your web server application
    (normally C\inetpub\wwwroot\global.asa)
  • ASP engine will run the code in the global.asa
    file in the following instance
  • The application starts (Application_OnStart
    event)
  • A session starts (Session_OnStart event)
  • A session ends (Session_OnEnd event)
  • The application ends (Application_OnEnd event)
  •  

21
Week 8 INTRINSIC ASP OBJECT
  • The Session Object (Cont..)
  • The ASP engine performs applicaton and session
    inialization in a specific order
  • The first person request a file from your
    application causes ASP to find the global.asa
    file in the applications root directory. The
    server performs the same steps whether or not the
    global.asa file exists.
  • Immediately after it creates the Application
    object, ASP calls the Application_OnStart event
    (if it exists).
  • When the Application OnStart event completes, the
    ASP engine creates a new SessionID, writes the
    SessionID cookie header, then creates a new
    Session Object and starts the Sessio.Timeout
    timer.
  • Immediately after it creates the new Session
    object, ASP calls the Session OnStart event (If
    it exists)
  • When the session times out or you issue a
    Session.Abandon command, the ASP engine calls the
    Session_OnEnd event procedure (if it exists ),
    then destroys the Session object.
  • After the ASP engine destroys the last Session
    object, it calls the Application_OnEnd event
    procedure (if it exists)

22
Week 8 INTRINSIC ASP OBJECT
  • The Session Object (Cont..)
  • The global.asa file is usefull when
  • Storing string references that might change
  • Cleaning up when a session ends
  • Ensuring that all users are out of your site.

23
Week 8 INTRINSIC ASP OBJECT
  • The Session Object (Cont..)
  • Example
  • if (Request.Form("password") selamat")
  • if(Session(sesi") "OK")
  • Response.Write("session has been
    successfully applied")
  • else
  • Response.Redirect("session_ex.asp")
  • gt
  • lthtmlgtltheadgtlt/headgtltbodygt
  • ltform action"session_ex.asp" method"post"gt
  • ltpgtPassword Please
  • ltinput typepassword namepassword gt
  • ltinput typesubmit name"toss" value"Submit"gt
  • lt/formgt
Write a Comment
User Comments (0)
About PowerShow.com