Hello World requires one Active Server Pages (ASP) page, which is stored as the file default.asp. Hello World's execution begins when the user requests the URL http://localhost/WebProjectName/Default.asp. Internet Information Server then loads the global.asa file, which is itself never seen by the user. There is always one and only one global.asa file in every ASP-based application. It exists in the root directory of the Web application and holds application-level and system-level variables. The global.asa file supports four subroutines for events at the start and end of the application and session. In the case of Hello World, it passes to the application the data source name (DSN) of the location of the SQL Server table storing the phrase "Hello World."
Note For information about ASP in a more complex application, see Active Server Pages in the CML. For information about creating the ODBC DSN, see Creating the Hello World DSN.
Here is the global.asa file:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
Application("Connection_String") = "DSN=HelloWorld"
End Sub
</SCRIPT>
After the application loads, the code in default.asp begins to execute. First, any HTML is sent to the client; the browser displays the header "Hello World Mini Sample" and the phrase "Hello World from HTML." The first line of code in the application tells the application not to maintain session state between hits on the page. The application retrieves the requested phrase from the database, returns it to the client, and disconnects.
<%@ Language=VBScript EnableSessionState=False%>
<% Option Explicit%>
<% 'Copyright Microsoft Corp. 1998-1999 %>
<HTML>
<HEAD>
<TITLE>Hello World Mini Sample</TITLE>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<h2> HELLO WORLD MINI SAMPLE </h2>
<h3>Hello World FROM HTML</h3>
Next, the application encounters the following lines that tell it to send the JavaScript code to the client. The application sends the code itself, which executes on the client. The JavaScript calls the DHTML document object, which is a client-side object. You cannot call server-side objects from client-side scripts.
<script language="JavaScript">
document.write('Hello World FROM JAVASCRIPT');
</script>
After the application sends the JavaScript code to the client, the application next encounters VBScript code. It was told in the first line of the ASP page to execute the VBScript code on the server and send the resulting HTML (or error information) to the client for display to the user.
<% Dim objHello,strLang
Response.Write "<p><b>" & "Hello world FROM ASP to " & _
Request.ServerVariables("REMOTE_HOST") & _
"</b><br>" & vbCrLf
This script retrieves the Internet Protocol (IP) address from the client computer and displays "Hello World from ASP to user's IP address." Next, the script makes a call into the Microsoft Transaction Server layer of the business-services tier and instantiates CHelloWorld, the public class of the Component Object Model (COM) component loaded into memory as Hello.dll. If the component cannot be created, the code branches to display an appropriate message to the user.
Set objHello = CreateObject("Hello.CHelloWorld")
If objHello Is Nothing Then
Response.Write "Unable to instantiate Hello object. Is it registered?"
Else
After the application creates the object without error, it uses the ASP Request object to find out the default language setting for the client's browser. It then uses the ASP Application object to pass the DSN, "Connection_String" to the object. Next, the application calls the SayHello method, passes it the client's default language, and then using the statement "Set objHello = Nothing" deactivates the component. In terms of the application's flow, the COM component executes within this block of code; the application leaves the ASP page and runs the code contained in the Visual Basic Class Modules.
strLang = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
objHello.ConnectionString = Application("Connection_String")
objHello.SayHello(strLang)
Set objHello = Nothing
End if
%>