Notes
Outline
ASP
A beginner’s Guide into Microsoft’s Premiere Web Technology
In the beginning…
HTML
Lacking Dynamic Content
Used to transmit information between computers, networks, and operating systems.
CGI (Common Gateway Interface)
First web interface.
Could be implemented in any number of programming languages.
First applications were actually programs written in C and C++.
Very cumbersome and time consuming.
Perl (Practical Extraction and Reporting Language)
Simplified version of C and C++, however still difficult to learn.
The Basics of Server Side Scripting
For a script to work with a Web Server there needs to be some kind of intermediate application, or add-in, to connect the two. It has to accept a request from the user, read and interpret the appropriate server-based script file, and then create the output page and communicate it to the Web server where it is sent as the response to the client.
Typically the task is divided into two sections.
One application or add-in handles the communication to and from the Web server. (CGI)
Another handles interpreting and executing the script.
Perl was the first such popular server-side scripting language.
Microsoft…
Internet Information Server (IIS) 1.0
Fairly standard offering.
Introduced an interface which allowed executables written in C and C++ to operate more efficiently.
ISAPI (Internet Server Application Programming Interface)
Provides the basis by which ASP connects to IIS, as well as the other Microsoft server-side dynamic techniques.
Comparing Technologies
The two major concerns when creating applications that interface the Web server are their effect on the stability of the Web server itself, and the efficiency with which they can handle multiple and concurrent page requests.
In-Process
ASP
Pros
Fast.
Can directly access input and output in the Web server’s memory address.
Cons
A failure or error in the code can bring down the Web server.
Out-of-Process
Out-of-Process
Perl and .exe files that use the ISAPI interface.
Pros
Failure of an out-of-process application will not affect the Web server.
Can be terminated by the user or operating system.
Cons
Slow.
Because access to the Web server’s memory is forbidden – any input or output must be passed to the server via a cross-process.
Latency caused by the loading and unloading of the executable.
In-Process
In-Process
ASP
Pros
Fast.
Can directly access input and output in the Web server’s memory address.
Cons
A failure or error in the code can bring down the Web server.
Processing an ASP File
When ASP receives a page from IIS that contains server-side script code, it parses it line-by-line. Anything that is not server-side script, is sent back to IIS, and onwards to the client. As each section of script is reached, it is passed to the appropriate scripting engine. The results of which are inserted at the appropriate points as it is sent to IIS.
Script is identified by either the <% %> script delimiters or by using the <SCRIPT> element.
Pages have an extension of .asp
The default scripting language is VBScript, however Jscript is a suitable alternative.
VBScript is NOT Visual Basic but is, in fact, a subset of the actual language.
Jscript IS based on Netscape’s JavaScript with the added feature of being able to be run at the server.
Hello World
<%Language=“VBScript”%>
<html>
<body>
<%
Response.Write(“Hello World”)
%>
</body>
</html>
The Intrinsic ASP Objects
Request
Response
Application
Session
Server
ASPError
Request
Makes available to our script all the information that the client provides when requesting a page or submitting a form. This includes the HTTP variables that identify the browser and the user, the cookies that they have stored on their browser for this domain, and any values appended to the URL, either as a query string or in HTML controls in a <FORM> section of the page.
Response
Is used to access the response that we are creating to send back to the client. It makes available to our script the HTTP variables that identify our server and its capabilities, information about the content we’re sending to the browser, and any new cookies that will be stored on their browser for this domain. It also provides the means by which we produce output – such as the Response.Write which we saw earlier.
Application
Provides a repository for storing variables and object references that are available to all the pages, which any visitor can open.
Session
Is created for each visitor when they first request and ASP page and remains until the default timeout period. Much like the application object, it provides a repository for storing variables and object references. Unlike the application object this repository remains in effect for the life of the session.
Server
Provides us with a series of methods and properties that are useful in scripting with ASP. The most obvious of which is the Server.CreatObject method, which allows us to properly instantiate other COM objects on to the server within the context of the current page or session.
ASPError
Is a new object in ASP 3.0, and is available through the GetLastError method of the Server object. It provides a range of detailed information about the last error that occurred in ASP.
Putting It All Together
Examples