OVERVIEW OF ASP What is ASP Active Server Pages (ASP), Microsoft respond to the Internet/E-Commerce fever, was designed specifically to simplify the process of developing dynamic Web applications. Built into Internet Information Server (IIS)Version 3.0 and later, ASP provides an easy-to-learn scripting interface along with a number of predefined objects that simplify many development tasks such as maintaining user state and defining global variables within an application. You can also use ActiveX components to perform additional functions, among them accessing ODBC databases and outputting data to text files. ASP is similar in concept to Allaire's Cold Fusion and Netscape's server-side JavaScript, and it is designed as a convenient alternative to conventional CGI scripting using Perl or C scripts. It's a great fit for a wide array of workgroup applications, including online human resources and accounting applications. Active Server Pages is an open, compile-free application environment in which you can combine HTML, scripts, and reusable ActiveX server components to create dynamic and powerful Webbased business solutions. Active Server Pages enables server side scripting for IIS with native support for both VBScript and Jscript. Microsoft Corp. ASP is a server-side scripting technology that can be used to create dynamic and interactive Web applications. 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 [1]. Why ASP One of the well-known problems of traditional Web applications development is that the Web's underlying protocol, HTTP, and its markup language, HTML, weren't designed to handle complex application logic. Traditional HTML authoring tools, such as NetObjects Fusion and Macromedia Dreamweaver, are great for document publishing and simple Web sites, but they don't address the issue of server-side Web applications development. Table 1 summarizes the available scripting techniques and their features.
Table 1: Summary of Scripting Techniques Technology Simple Scripting Traditional CGI scripts lack built-in transaction and object orientation. Template-based Scripting HTML template files combined with application code written in a scripting language. This method provides transaction capabilities and simple object orientation. Application Servers Dedicated servers that handle application logic, usually written in C++ or Java. They provide sophisticated transaction capabilities and complex object models. Sample Products Fault Tolerance and Scalability Best fit CGI None Simple Web sites Allaire's Cold Fusion Microsoft s Active Server Pages (ASP) Netscape's serverside JavaScript NetDynamics Netscape s Application Server (Kiva) None Built-in fault tolerance and loadbalancing capabilities Workgroup applications High performance applications with complex business logic Unique Features of ASP ASP is a browser-independent technology. No matter which browser -- Internet Explorer, NCSA Mosaic, or Netscape Navigator -- visitors to your site are using, your ASP code generates HTML. ASP is designed to be language-independent; therefore, you can choose the language you want to use to write your server-side scripts. ASP is implemented as an ISAPI application integrated into IIS. As a result, ASP doesn't incur the performance overhead common to CGI applications, which spawn individual processes for every new request that goes through the Web server. With IIS 4.0, a single ISAPI process handles all ASP requests. Also, ASP can be run out-ofprocess from IIS, meaning that an ASP crash won't take the Web server down as well. With ASP, one can separate the design of your Web page from the nitty-gritty details of programming access to databases and applications. ASP runs as a service of the Web server and is optimized for multiple threads and multiple users.
What Can ASP Do ASP can be used to perform the following tasks: Store application variables. Retrieve browser request information. Handle dynamic and live data. E.g., Changes in pricing data were automatically reflected in the catalog's HTML pages. Uses ActiveX Data Objects (ADOs) to access data in ODBC-compliant databases such as Microsoft Access or SQL Server. Retrieve and modify data in text files on the server's file system (TextStream). Create instances of ActiveX objects. Examples of ASP Applications ASP can be used to design web page for many usages. Here are just a few selected examples of ASP applications. Put your employee handbook online, rather than printing copies that are soon obsolete. Employees can access and update their own records, such as address and health-plan benefits. Customers could update and manipulate selected data (e.g., shipping address and contact information). Tie online store to existing inventory database and order-processing system. Give every visitor to your site a personalized view of just the information he or she seeks, and automatically flag what is new since the last visit. How ASP Work When you create an ASP application, you create ASP script files: plain text files comprising a combination of standard HTML code and script commands. While Web servers normally send HTML files directly to the client's Web browser in response to HTTP requests, IIS first processes the content of ASP scripts before sending output to clients. Within an ASP script, standard HTML code is sent directly to the browser, while script commands are executed locally on the Web server. The diagram below shows the life cycle of an ASP page. We can break this life cycle into three distinct phases: the request, the processing, and the response. If you've used Common Gateway Interface (CGI), you'll find this very familiar. The request phase represents the initial point of contact between the user's Web browser and your ASP file. The user activates the ASP code by browsing into the file that contains your code (usually identifiable by its.asp filename extension). The first time a user visits your ASP application, IIS creates a Session object you can use to manage that user's context within your ASP application. If the user has already visited another ASP file in your ASP application (we'll see below what constitutes an ASP application), IIS will
update the state of the user's existing Session object. Once the Session object has been initialized, IIS begins executing the code in your ASP file. A user's Web browser can pass parameters to your ASP code through the file request command line. The arguments are processed by IIS and stored in a Request object that can be accessed by the code in the ASP page. For example, the HTTP GET request http://www.iunknown.com/story.asp?storyid=5 tells IIS there is a named argument called StoryID and its value is 5. The processing phase begins once IIS has initialized the Session and Request objects. IIS executes the ASP code and interacts with various databases or other ActiveX components according to your instructions. As IIS extracts and processes data from your ActiveX components, it can also generate the HTML page that will be sent back to the user's Web browser. After your ASP script finishes executing, the response phase begins. At this point, IIS again steps in to package the HTML page to ship back to the user's Web browser. Your page can contain anything that can be included in an HTML page. The one thing that it cannot contain, however, is live data. We will see later how Remote Data Service lets us solve this problem. Built-in Objects ASP includes five standard objects for global use: Request to get information from the user Response to send information to the user Server to control the Internet Information Server Session to store information about and change settings for the user's current Web-server session Application to share application-level information and control settings for the lifetime of the application
The Request and Response objects contain collections (bits of information that are accessed in the same way). Objects use methods to do some type of procedure and properties to store any of the object's attributes (such as color, font, or size). The Request object The Request object is used to get information from the user that is passed along in an HTTP request. It supports the following collections: ClientCertificate to get the certification fields from the request issued by the Web browser. The fields that you can request are specified in the X.509 standard. QueryString to get text such as a name, and favorite TV, et. Form to get data from an HTML form. Cookies to get the value of application-defined cookie. ServerVariables to get HTTP information such as the server name. The Response object The Response object is used to send information to the user. The Response object supports only Cookies as a collection (to set cookie values). The properties currently supported by Response object are: Buffer set to buffer page output at the server. When this is set to true, the server will not send a response until all of the server scripts on the current page have been processed, or until the Flush or End method has been called. ContentType to set the type of content (i.e: text/html, Excel, etc.). Expires sets the expiration (when the data in the user's cache for this Web page is considered invalid) based on minutes (i.e.: expires in 10 minutes). ExpiresAbsolute allows you to set the expiration date to an absolute date and time. Status returns the status line (defined in the HTTP specification for the server). The following methods are supported by the Response object: AddHeader Adds an HTML header with a specified value. AppendToLog Appends a string to the end of the Web server log file. BinaryWrite writes binary data (i.e, Excel spreadsheet data). Clear clears any buffered HTML output. End stops processing of the script. Flush sends all of the information in the buffer. Redirect to redirect the user to a different URL. Write to write into the HTML stream. This can be done by using the construct - Response.write("hello") or the shortcut command <%="hello"%> The Server object
The Server object supports one property, ScriptTimeout, which allows you to set the value for when the script processing will time out. It supports the following methods: CreateObject to create an instance of a server component. This component can be any component that you have installed on your server (such as an ActiveX ). HTMLEncode to encode the specified string in HTML. MapPath to map the current virtual path to a physical directory structure. You can then pass that path to a component that creates the specified directory or file on the server. URLEncode applies URL encoding to a specified string. The Session object The Session object is used to store information about the current user's Web-server session. Variables stored with this object exist as long as the user's session is active, even if more than one application is used. This object supports one method, Abandon, which (believe it or not!) abandons the current Web-server session, destroying any objects, and supports two properties, SessionID, containing the identifier for the current session, and Timeout, specifying a time-out value for the session. One thing to bear in mind about the session identifier: It's not a GUID. It's only good as long as the current Web-server session is running. If you shut down the Web-server service, the identifiers will start all over again. So don't use it to create logon IDs, or you'll have a bunch of duplicates and one heck of a headache. The Application object The Application object can store information that persists for the entire lifetime of an application (a group of pages with a common root). Generally, this is the whole time that the IIS server is running. This makes it a great place to store information that has to exist for more than one user (such as a page counter). The downside of this is that since this object isn't created anew for each user, errors that may not show up when the code is called once may show up when it is called 10,000 times in a row. In addition, because the Application object is shared by all the users, threading can be a nightmare to implement. References 1. Active Server Pages Tutorial, Microsoft Corporation. URL: http://msdn.microsoft.com/workshop/server/asp/asptutorial.asp 2. John Garris, Scripting with ASP. URL: http://www.zdnet.com/pcmag/pctech/content/17/12/nt1712.001.html 3. John Lam, Database Connectivity and the Internet: Active Server Pages and Remote Data Service. URL: http://www.zdnet.com/pcmag/pctech/content/16/22/it1622.001.html 4. ASP Today. URL: http://www.asptoday.com/ 5. Source Codes, WROX Publisher. URL: http://www.wrox.com/consumer/store/download.asp?category=consumer 6. Cluts, Nancy Winnick An ASP You Can Grasp: The ABCs of Active Server Pages. URL: http://msdn.microsoft.com/workshop/server/asp/aspover.asp
7. Wodaski, Ron, ASP Technology Feature Overview. URL http://msdn.microsoft.com/workshop/server/asp/aspfeat.asp 8. Cluts, Nancy Winnick, 25+ ASP Tips to Improve Performance and Style. URL: http://msdn.microsoft.com/workshop/server/asp/asptips.asp 9. Cluts, Nancy Winnick, ASP from A to Z. URL: http://msdn.microsoft.com/workshop/server/asp/aspatoz.asp 10. Moran, Tom, Ask Tom: Server Q & A. URL: http://msdn.microsoft.com/workshop/server/feature/morqa.asp