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 :
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
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.
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.
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
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
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)
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
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
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.
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.
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.
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