ASP Objects Active Server Pages (cont..) 1. 2 ASP : Objects ASP provides built-in objects for performing useful tasks that simplify web development.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
CIS 451: ASP Sessions and Applications Dr. Ralph D. Westfall January, 2009.
1 Chapter 12 Working With Access 2000 on the Internet.
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
Basic Scripting in VBScript  VBScript must enclosed by  No HTML code is allowed inside a VBScript code block  Nested scripting block is not allowed.
Client State Management & Application Security  Client State Management  Concept  ASP Examples  Application Security  Database Based Approach 
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 1.
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
Week 9 PHP Cookies and Session Introduction to JavaScript.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Chapter 8 Cookies And Security JavaScript, Third Edition.
CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
Chapter 6 Server-side Programming: Java Servlets
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
ASP.NET Dynamic Styles Response and Request Objects.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP (COMPONENTS) Active Server Pages (cont..) 1. global.asa file The Global.asa file is an optional file that can contain declarations of objects, variables,
ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
Maintaining State in ASP. Problem - How do I maintain state information about the user  Several Methods –Cookies –Session variables –Hidden fields 
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Active Server Pages Session - 3. Response Request ApplicationObjectContext Server Session Error ASP Objects.
Raina NEC Application Object Describes the methods, properties, and collections of the object that stores information related to the entire Web.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
ASP Explained By: Sarbjit Kaur.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
The Request & Response object
ASP.
Client side & Server side scripting
Browser and Server Models
Configuring Internet-related services
Chapter 2 Interacting with the Customer
Cookies A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer.
Presentation transcript:

ASP Objects Active Server Pages (cont..) 1

2

ASP : Objects ASP provides built-in objects for performing useful tasks that simplify web development. The built-in objects are automatically created for the user when the ASP request starts processing. The user can access the methods and properties of a built-in object to control sessions and web-server applications. 3

ASP-Objects An object has methods, properties and collections. – Methods determine the things that one can do with the object – Property is an attribute that describes an object – Collection constitutes different sets of key and value pairs related to the object 4

Object Property Syntax: Object.Property Properties of an Object can be set by using the assignment operator “=“ 5 Object Method Syntax for calling a method : Object.Method parameters Eg. Response.write “Hello World!” ObjectParameterMethod

ASP provides the following built-in-objects: 1.Application Object : To share information among all users of an application. 2.Request Object : To gain access to any information that is passed with an HTTP request the browser to the server. This includes parameters passed from an HTML form using either GET or POST methods and cookies etc. 3.Response Object : To control the information sent back to the browser from the server. 4.Server Object : This provides access to methods and properties on the server. Server object can be used to control script execution time, to create other objects. 5.Session Object : To store information required for a particular user session. 6.ASPError Object : To trap ASP errors and return more informative description to the users. 6

7 Request Object Response Object Session Object Client Request Server ASP Error Object Server Object Server Response Application Object

8 RESPONSE OBJECT Response and Request objects provide the user with complete control over how the Web server communicates with Web browsers. When a Web server receives a request, it returns an HTTP response. If the Web server has problems with the request, it returns an error and a description of the error in the status line. Request ObjectResponse Object An object holding information that the client sends to the server as an HTTP request. An object holding information that the server sends to the client as an HTTP response. Contains the Cookies, Form, QueryString and ServerVariables collection. Contains the Cookies collection.

Properties of Response Object 9 PropertySyntaxDescription Buffer Response.Buffer [=TRUE | FALSE] False indicates no buffering and is the default. True indicates buffering. Indicates whether the page output is buffered or not. Content Type Response.ContentType [=ContentType] Content type is a string describing the content type in the format type/sub-type, eg., “text/HTML” or “image/GIF” By default the content type is text/HTML Expires Response.Expires [=number] number is the time in minutes before the page expires. Expires Absolute Response.ExpiresAbsolute [ = [date] [time]] If time is not mentioned then the page expires at midnight. The date / time at which a page cached on a browser expires. If date is not mentioned then expires at the time on the day the script is run. Status Response.Status=[StatusDescription] Specifies the value of the status line returned by the server.

Methods of Response Object 10 MethodDescription AddHeaderSets the HTML header name to value. AppendToLogAdds a string to the end of the Web server log entry for this request. BinaryWriteWrites the given information to the current HTTP output without any character-set conversion. ClearErases any buffered HTML output. EndStops processing the.asp file and returns the current result. FlushSends buffered output immediately. RedirectSends a redirect message to the browser, causing it to attempt to connect to a different URL WriteWrites a variable or text to the current HTTP output as a string.

Methods of Response Object 11 MethodSyntax AddHeader Response.AddHeader HeaderName, HeaderValue AppendToLog Response.AppendToLog string e.g., BinaryWrite Response.BinaryWrite data ClearResponse.Clear EndResponse.End FlushResponse.Flush RedirectResponse.Redirect URL e.g., WriteResponse.Write variant e.g.,

12 Difference between Response.Clear and Response.Flush Response.ClearResponse.Flush Clear method clears any buffered HTML output. The Flush method sends buffered HTML output immediately. Buffer is cleared without contents being displayed. Displays output on screen and then buffer is cleared.

13 REQUEST OBJECT All communication between a browser and a Web server takes place in discrete Request-Response pair. An HTTP request contains a Header line, header fields and a message. Syntax : Request.[Collection] (variable) Form Collection : The FORM collection retrieves the values of form elements posted to the HTTP request body, with a form using POST method Syntax : Request.Form (element) [ (index) |.Count ] Where element is the name of the form element from which the collection is to retrieve values.

14 Form Your First Name : What is your favourite colour : Red Blue Yellow Green Next Page Welcome, Your favourite colour is. Form contains a text field fname, a selection list fcolour and a submit button Firstpage.asp Nextpage.asp

15 The QueryString Collection Syntax : Request.QueryString (Variable) [ (index) |.Count] where Variable specifies the name of the variable in the HTTP query string to retrieve. Choice What is your favourite colour ? Red Blue Green Choice.asp Choice Next Your favourite colour is > ! Choicenext.asp

16 ServerVariables Collection The ServerVariable collection retrieves the values of pre-determined environment variables. Syntax : Request.ServerVariables (server environment variable) The server environment variable can be one of the following: HTTP_USER_AGENT – returns a string describing the browser that sent the request. REMOTE_ADDR – the IP address of the remote host making the request., i.e., the IP address of the client. REMOTE_HOST – the name of the host making the request. SERVER_NAME – server’s host name, DNS alias or IP address as it would appear in self-referencing URLs. Browser Used: IP address of client: DNS Host: Host Server:

17 Cookies Collection A Cookie is an ASP object that allows a programmer to store user data either on the Web server or on the Client’s computer in C:\Windows\Cookies for retrieval and use later. When a visitor opens a page, the script instructs the browser to create the cookie. Creating Cookies Response.Cookies (cookie) [.attribute] = value Where cookie is the name of the cookie, attribute specifies information about the cookie itself, this can be one of the following. Retrieving values from a cookie Request.Cookies (cookie) [.attribute] NameDescription DomainWrite-only, if specified, the cookie is sent only to this domain ExpiresWrite-only, the date on which the cookie expires. HashKeysRead-only, specifies if the cookie contains key PathWrite-only, if specified, the cookie is sent to this address SecureWrite-only, specifies whether the cookie is secure

18 <% Response.Cookie (“Location “) = “India” Response.Cookie (“Location “).Expires = “December 31,2013” %> Creates a cookie named Location and assigns the value India and expires on December 31,2013

19 <% If (request.cookies (“NumVisits”)=” “) Then Response.Cookies (“NumVisits”) = 0 Else Response.Cookies (“NumVisits”) = Request.Cookies (“NumVisits”) + 1 End if %> Using Cookies in ASP Welcome to ASP with cookies Welcome! First time you are visiting this page! Thanks for visiting this page again! You have visited this page a total of times. Time is Date is 0) THEN %> You last accessed this web page on at

20 Application Object A group of related Active server Pages is called an application. This group of ASP files work together to perform a specific task. The Application Object in ASP bind together these files. The Application Object is used to store and retrieve information that can be shared among all users of an application. Application Variable <% Application (“Greetings”) = “Hello!” %> A new application variable Greetings is created and assigned the value Hello! The value of the application variable is outputted to the browser Once the application variable has been assigned a value, it retains that value until the Web server is shut down or the application is unloaded.

21 To initialize variables in the Application object, the information about them is stored in a special ASP file (optional) named global.asa which contains the information that is global to the application. An application can have only one global.asa file and it is stored in the root directory of the application. Application Object Collections: contents : contains all items that have been added to the application through a script command Syntax : Application.contents (“Key”) where Key specifies the name of the item to retrieve. The number of elements in the collection can be retrieved by using Count property. Methods of Application Object MethodDescription LockBlocks other clients from modifying the variables stored in the Application Object, ensuring only one client at a time can alter or access the Application variable. UnLockRemoves the lock from the variables stored in the Application object. Contents.RemoveRemoves an item from the Contents collection Contents.RemoveAllRemoves all items from the Contents collection

22 Example: <% Application.Lock ClickCount=Application(“BannerClick”) ClickCount=ClickCount+1 Application(“BannerClick”) = ClickCount Application.Unlock %> Remove Method deletes an item from a collection Syntax : Application.Contents.Remove ( name | index ) Where name is the identifier for the item to be removed, index is an index offset indicating which item in the list to be removed Remove All Method deletes all the items from a collection Syntax : Application.Contents.RemoveAll Application(“FirstVar”) = “apples” Application(“SecondVar”) = “oranges” Application.Contents.Remove(“FirstVar”) Will create 2 application variables FirstVar and SecondVar then removes the variable FirstVar. Application(“FirstVar”) = “apples” Application(“SecondVar”) = “oranges” Application.Contents.RemoveAll() Will create 2 application variables FirstVar and SecondVar then removes all the variables in the collection

23 Session Object Session starts when the user requests a page from a web-site, the Web server automatically creates a Session object and end soon after the user leaves. Session Variables: Session Example <% Session(“UserName”) = “john” Session(“Age”)=17 %> 2 session variables UserName and Age are initialized. Page1.asp Second Page Welcome You are years old. Page2.asp When user views Page2.asp it will display user’s name and age that was assigned in Page1.asp

24 Properties of Session Object SessionID – Session.SessionID - Returns the session identifier, a unique identifier that is generated by the server when the session is created. TimeOut – Session.TimeOut – Specifies the time out period assigned to the Session object for the application. Methods of Session Object Abandon – Session.Abandon – Destroys all the objects stored in the Session Contents.Remove – Session.Contents.Remove [Item / Index] – Removes a specific item from the Session object’s Contents collection. Contents.RemoveAll – Session.Contents.RemoveAll() – Removes all items from the Session object’s Contents collection.

25 Server Object Server object enables the use of the various utility functions on the server like creating instances of other objects. Property of Server Object: ScriptTimeOut – Server.ScriptTimeOut = where represents maximum number of seconds the script can execute before the server terminates it, default time is 90 seconds. Methods of the Server Object: 1.CreateObject: Creates an instance of the server component. This instance as page scope, automatically destroyed by the server after processing of the current ASP page. ServerCreateObject(progID), where progID specifies the type of object to create. 2. Execute: Executes an.asp file. Server.Execute(path), path is the location of the.asp file. 3. GetLastError: Returns an ASPError object that describes the error condition. Server.GetLastError() 4. Transfer: Sends all the current information to another.asp file for processing Server.Transfer (path)

26 Examples First.asp FIRST PAGE <% Response.write “ Welcome to First Page %> Second.asp SECOND PAGE <% Response.write “ This is Second Page %> Server_transfer.asp Executing and Transfer <% Response.write “Original Page” Server.Execute “First.asp” Response.write “ Back to original Page Server.Transfer “Second.asp” Response.write “ Once again back to original Page

27 ASPError Object This object is used to obtain information about an error condition that has occurred in the script in ASP page. ASPError object is returned by the Server.GetLastError method. Properties of ASPError Object: ASPCode – ASPError.ASPCode()- Returns the ASP error code Number - ASPError.Number()- Returns the COM error code Source – ASPError.Source() – Returns the portion of the code that caused the error. Category - ASPError.Category() – Returns whether the error is occurred by the script or the object of the ASP. File - ASPError.File() - Returns the name of file in which the error is located. Line - ASPError.Line() - Returns the line number of the script where the error is located. Column - ASPError.Column() – Returns the column within the file where the error is located. Description - ASPError.Description() - Returns short description of the error. ASP Description - ASPError.ASPDescription() - Returns detailed description of the error.