Anda di halaman 1dari 18

BHARTI VIDYAPEETH DEEMED UNIVERSITY COLLEGE OF ENGINEERING , PUNE

Seminar Report On ACTIVE SERVER PAGES - OBJECTS AND COMPONENTS For The Subject WEB TECHNOLOGY Submitted By Rajani Maheshwari M.Tech (Computer ) Sem - II Roll No. 9 Deliverd On : 9th March, 2011

Date :

Prof. D.M.Thakore ( Seminar Guide )

Table of Contents :
Sr.No.
1.

Topic
Introduction to Active Server Pages 1.1 Compare and contrast ASP with standard HTML ASP Object Model 2.1 Request Object 2.2 Response Object

Page No.
3 3 5 6 7 8 10 11 12 13 13 14 16 17 18

2.

2.3 Application Object 2.4 Session Object 2.5 Server Object 2.6 The ASPError Object Components of ASP 3.1 ASP AdRotator Component 3.2 ASP Browser Capabilities Component

3.

3.3 ASP Content Linking Component 3.4 ASP Content Rotator Component 3.5 ADO

List of Figures :
Sr.No.
1. 2. 3.

Topic
Introduction to Active Server Pages Introduction to Active Server Pages ASP Object Model

Figures
An HTML page Execution An ASP Page Execution ASP Object Model

Page No.
4 4 6

1. Introduction to ASP
2

ASP is a powerful tool for making dynamic and interactive Web pages. Developing functionality in ASP websites is enabled by the active scripting engine's support of the Component Object Model (COM), with each object providing a related group of frequently-used functions and data attributes. An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are executed on the server.Microsoft Active Server Pages (ASP) is a server-side scripting environment that you can use to create and run dynamic, interactive Web server applications. With ASP, you can combine HTML pages, script commands, and COM components to create interactive Web pages and powerful Web-based applications that are easy to develop and modify. An ASP page is an HTML page that contains server-side scripts that are processed by the Web server before being sent to the user's browser. You can combine ASP with Extensible Markup Language (XML), Component Object Model (COM), and Hypertext Markup Language (HTML) to create powerful interactive Web sites. Server-side scripts run when a browser requests an .asp file from the Web server. ASP is called by the Web server, which processes the requested file from top to bottom and executes any script commands. It then formats a standard Web page and sends it to the browser.

1.1

Compare and contrast ASP with standard HTML


When a browser requests an HTML file, the server returns the file. When a

browser requests an ASP file, IIS passes the request to the ASP engine. The ASP engine reads the ASP file, line by line, and executes the scripts in the file. Finally, the ASP file is returned to the browser as plain HTML.

Figure 1 : An HTML page Execution

Figure 2 : An ASP Page Execution

2. ASP Object Model


Active Server Pages consist of six built in objects. They are ready-made objects which provide functionality to your web pages without requiring you to make custom objects (though you can if you want to, later on that topic). This page contains only reference material on the methods, properties and events available in these objects, if you are not sure how to make use of them then please first go through an introductory article or tutorial on Active Server Pages then come back here. The reference material listed here pertains to the ASP 3.0 object model which Microsoft has introduced in IIS 5.0 (windows 2000). Following are the six built in ASP objects:

Application ASPError ObjectContext Request Response Server Session

For instance, in Web development, it started with information publishing using HTML. Then people got bored of static content. This forced us to give some dynamic behavior to the site. We started adding interactive features and now we have come to a stage of developing data intensive application over the web. And we cannot rely on the scripts alone to deliver all goods for us. There is a strong urge to reduce the repetitive tasks. Precisely, in any database application, we need to have forms to get data from the user.

Figure 3 : ASP Object Model

2.1 Request Object


When a browser asks for a page from a server, it is called a request. The Request object is used to get information from a visitor. Its collections, properties, and methods are described below: Collections Collection ClientCertificate Cookies Form QueryString ServerVariables Properties Property TotalBytes Description Returns the total number of bytes the client sent in the body of the request Methods 6 Description Contains all the field values stored in the client certificate Contains all the cookie values sent in a HTTP request Contains all the form (input) values from a form that uses the post method Contains all the variable values in a HTTP query string Contains all the server variable values

Method BinaryRead

Description Retrieves the data sent to the server from the client as part of a post request and stores it in a safe array

2.2 Response Object


The ASP Response object is used to send output to the user from the server. Its collections, properties, and methods are described below: Collections Collection Cookies Description Sets a cookie value. If the cookie does not exist, it will be created, and take the value that is specified Properties Property Buffer CacheControl Charset ContentType Expires ExpiresAbsolute IsClientConnected Pics Status Methods Method Description 7 Description Specifies whether to buffer the page output or not Sets whether a proxy server can cache the output generated by ASP or not Appends the name of a character-set to the content-type header in the Response object Sets the HTTP content type for the Response object Sets how long (in minutes) a page will be cached on a browser before it expires Sets a date and time when a page cached on a browser will expire Indicates if the client has disconnected from the server Appends a value to the PICS label response header Specifies the value of the status line returned by the server

AddHeader AppendToLog BinaryWrite Clear End Flush Redirect Write

Adds a new HTTP header and a value to the HTTP response Adds a string to the end of the server log entry Writes data directly to the output without any character conversion Clears any buffered HTML output Stops processing a script, and returns the current result Sends buffered HTML output immediately Redirects the user to a different URL Writes a specified string to the output

2.3 Application Object


An application on the Web may consists of several ASP files that work together to perform some purpose. The Application object is used to tie these files together. The Application object is used to store and access variables from any page, just like the Session object. The difference is that ALL users share ONE Application object (with Sessions there is ONE Session object for EACH user). The Application object holds information that will be used by many pages in the application (like database connection information). The information can be accessed from any page. The information can also be changed in one place, and the changes will automatically be reflected on all pages. The Application object's collections, methods, and events are described below: Collections Collection Contents StaticObjects Description Contains all the items appended to the application through a script command Contains all the objects appended to the application with the HTML <object> tag Methods Method Contents.Remove Description Deletes an item from the Contents collection 8

Contents.RemoveAll() Lock Unlock

Deletes all items from the Contents collection Prevents other users from modifying the variables in the Application object Enables other users to modify the variables in the Application object (after it has been locked using the Lock method)

Events Event Application_OnEnd Application_OnStart Description Occurs when all user sessions are over, and the application ends Occurs before the first new session is created (when the Application object is first referenced)

2.4 Session Object


When you are working with an application on your computer, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you open the application and when you close it. However, on the internet there is one problem: the web server does not know who you are and what you do, because the HTTP address doesn't maintain state. ASP solves this problem by creating a unique cookie for each user. The cookie is sent to the user's computer and it contains information that identifies the user. This interface is called the Session object. The Session object stores information about, or change settings for a user session. Variables stored in a Session object hold information about one single user, and are available to all pages in one application. Common information stored in session variables are name, id, and preferences. The server creates a new Session object for each new user, and destroys the Session object when the session expires. The Session object's collections, properties, methods, and events are described below:

Collections Collection Contents StaticObjects Description Contains all the items appended to the session through a script command Contains all the objects appended to the session with the HTML <object> tag Properties Property CodePage LCID Description Specifies the character set that will be used when displaying dynamic content Sets or returns an integer that specifies a location or region. Contents like date, time, and currency will be displayed according to that location or region SessionID Timeout Returns a unique id for each user. The unique id is generated by the server Sets or returns the timeout period (in minutes) for the Session object in this application Methods Method Abandon Contents.Remove Contents.RemoveAll() Events Event Session_OnEnd Session_OnStart Description Occurs when a session ends Occurs when a session starts Description Destroys a user session Deletes an item from the Contents collection Deletes all items from the Contents collection

2.5 Server Object


10

The ASP Server object is used to access properties and methods on the server. Its properties and methods are described below: Properties Property ScriptTimeout Description Sets or returns the maximum number of seconds a script can run before it is terminated Methods Method CreateObject Execute GetLastError() HTMLEncode MapPath Transfer URLEncode Description Creates an instance of an object Executes an ASP file from inside another ASP file Returns an ASPError object that describes the error condition that occurred Applies HTML encoding to a specified string Maps a specified path to a physical path Sends (transfers) all the information created in one ASP file to a second ASP file Applies URL encoding rules to a specified string

2.6 The ASPError Object


The ASPError object was implemented in ASP 3.0 and is available in IIS5 and later.The ASPError object is used to display detailed information of any error that occurs in scripts in an ASP page. The ASPError object is created when Server.GetLastError is called, so the error information can only be accessed by using the Server.GetLastError method.The ASPError object's properties are described below (all properties are readonly): Properties

11

Property ASPCode ASPDescription Category Column Description File Line Number Source

Description Returns an error code generated by IIS Returns a detailed description of the error (if the error is ASPrelated) Returns the source of the error (was the error generated by ASP? By a scripting language? By an object?) Returns the column position within the file that generated the error Returns a short description of the error Returns the name of the ASP file that generated the error Returns the line number where the error was detected Returns the standard COM error code for the error Returns the actual source code of the line where the error occurred

3. ASP COMPONENTS
3.1 ASP AdRotator Component
The ASP AdRotator component creates an AdRotator object that displays a different image each time a user enters or refreshes a page. A text file includes information about the images. Syntax <% set adrotator=server.createobject("MSWC.AdRotator") adrotator.GetAdvertisement("textfile.txt") %> Example Assume that we have the following text file, named "ads.txt": REDIRECT banners.asp * 12

w3s.gif http://www.w3schools.com Free Tutorials from W3Schools 50 xmlspy.gif http://www.altova.com XML Editor from Altova 50 The lines below the asterisk in the text file above specifies the name of the images (ads) to be displayed, the hyperlink addresses, the alternate text (for the images), and the display rates (in percent).The first line in the text file above specifies what to happen when a visitor clicks on one of the images. The redirection page (banners.asp) will receive a querystring with the URL to redirect to.

3.2 ASP Browser Capabilities Component


The ASP Browser Capabilities component creates a BrowserType object that determines the type, capabilities and version number of a visitor's browser.When a browser connects to a server, a User Agent header is also sent to the server. This header contains information about the browser.The BrowserType object compares the information in the header with information in a file on the server called "Browscap.ini".If there is a match between the browser type and version number in the header and the information in the "Browsercap.ini" file, the BrowserType object can be used to list the properties of the matching browser. If there is no match for the browser type and version number in the Browscap.ini file, it will set every property to "UNKNOWN". Syntax <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %>

13

Example The example below creates a BrowserType object in an ASP file, and displays some of the capabilities of your browser: <html> <body> <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %> <table border="0" width="100%"> <tr> <th>Client OS</th><th><%=MyBrow.platform%></th> </tr><tr> <td >Web Browser</td><td ><%=MyBrow.browser%></td> </tr><tr> <td>Browser version</td><td><%=MyBrow.version%></td> </tr><tr> <td>Frame support?</td><td><%=MyBrow.frames%></td> </tr><tr> <td>Table support?</td><td><%=MyBrow.tables%></td> </tr><tr> <td>Sound support?</td><td><%=MyBrow.backgroundsounds%></td> </tr><tr> <td>Cookies support?</td><td><%=MyBrow.cookies%></td> </tr><tr> <td>VBScript support?</td><td><%=MyBrow.vbscript%></td> </tr><tr> <td>JavaScript support?</td><td><%=MyBrow.javascript%></td> </tr> </table> 14

</body> </html> The Browscap.ini File The "Browsercap.ini" file is used to declare properties and to set default values for browsers.This section is not a tutorial on how to maintain "Browsercap.ini" files, it only shows you the basics; so you get an idea what a "Browsercap.ini" file is all about.

3.3 ASP Content Linking Component


The ASP Content Linking component is used to create a quick and easy navigation system!The Content Linking component returns a Nextlink object that is used to hold a list of Web pages to be navigated. Syntax <% Set nl=Server.CreateObject("MSWC.NextLink") %> Example First we create a text file - "links.txt": asp_intro.asp ASP Intro asp_syntax.asp ASP Syntax asp_variables.asp ASP Variables asp_procedures.asp ASP Procedures The text file above contains the pages to be navigated. The pages must be listed in the same order you want them to be displayed, and it must also contain a description for each file name (use the tab key to separate file name from description). Then we create an

15

include file, "nlcode.inc". The .inc file creates a NextLink object to navigate between the pages listed in "links.txt". "nlcode.inc": <% dim nl Set nl=Server.CreateObject("MSWC.NextLink") if (nl.GetListIndex("links.txt")>1) then Response.Write("<a href='" & nl.GetPreviousURL("links.txt")) Response.Write("'>Previous Page</a>") end if Response.Write("<a href='" & nl.GetNextURL("links.txt")) Response.Write("'>Next Page</a>") %> In each of the .asp pages listed in the text file "links.txt", put one line of code: <!-#include file="nlcode.inc"-->. This line will include the code in "nlcode.inc" on every page listed in "links.txt" and the navigation will work.

3.4 ASP Content Rotator Component


The ASP Content Rotator component creates a ContentRotator object that displays a different content string each time a visitor enters or refreshes a page. A text file, called the Content Schedule File, includes the information about the content strings. The content strings can contain HTML tags so you can display any type of content that HTML can represent: text, images, colors, or hyperlinks. Syntax <% Set cr=Server.CreateObject("MSWC.ContentRotator") %> 16

Example The following example displays a different content each time a visitor views the Web page.First, create a text file named "textads.txt" and place it in a subfolder called "text". "textads.txt": %% #3 <h2>This is a great day!!</h2> %% #3 <img src="smiley.gif"> %% #4 <a href="http://www.w3schools.com">Visit W3Schools.com</a> Notice the #number at the beginning of each content string. This number is an optional parameter that indicates the relative weight of the HTML content string. In the text file above, the Content Rotator will display the first and second content string three-tenth of the time, and the third string four-tenths of the time.Then, create an ASP file, and insert the following code: <html> <body> <% set cr=server.createobject("MSWC.ContentRotator") response.write(cr.ChooseContent("text/textads.txt")) %> </body> </html>

3.5 ADO
ADO is a Microsoft technology.ADO stands for ActiveX Data Objects.ADO is a Microsoft Active-X component.ADO is automatically installed with Microsoft IIS.ADO is a programming interface to access data in a database. 17

18