You are on page 1of 78

Appendices

Lab 1: Introduction to Active Server

Objectives

What You Will Learn


After completing this lab, you will be able to:
• Create basic script examples, demonstrating how to associate code with events or run inline.
• Create a script that combines client side and server side scripting.

Related Topics Covered in this Lab


• Client Side Scripting

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Before You Begin


Prerequisites
This lab requires that Microsoft Internet Information Server version 4.0 is installed on the local machine
Estimated time to complete this lab: 30 minutes

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 1
Comparing Client Side and Server Side
Scripts
In this exercise, you will create client side and server side script files, comparing the behavior of each.
The purpose of this exercise is to demonstrate similarities and differences between server script and client
script, not code structure. Exercises in subsequent lessons will focus on more closely on the code.
1. To create the client side script example:
• Launch NOTEPAD.EXE and insert the following code example into a new document.
<HTML>
<BODY>
This is a simple VBScript Demo.
It calculates the number of days until the end of the year.
<Script Language="VBScript">
<!--
Sub Window_OnLoad
Dim iTargetYear, dTargetDate, iDateDiff

iTargetYear=Year(Date())
dTargetDate=DateSerial(iTargetYear,12,31)
iDateDiff=DateDiff("d",Date(),dTargetDate)
Msgbox "Today's date is " & Date()
Msgbox iDateDiff & " more days to year end."

End Sub
-->
</Script>
</Body>
</HTML>
• Save the file as C:\INETPUB\WWWROOT\CLIENTDEMO.HTM.
• Launch Microsoft Internet Explorer and test the sample by browsing
HTTP://LocalHost/CLIENTDEMO.HTM. Allow the program to complete, dismissing the message box
by clicking the button marked “OK”.
• In IE, view the HTML source of the client program by selecting the Source menu item from the View
menu.
What information is available in the Source? Is the script code visible? With what event is the script
associated (hint: look at the name of the sub procedure).

d Support Training Microsoft ConfidentialOctober 2008


Appendices

2. To create the server side script example:


• Launch NOTEPAD.EXE and insert the following code example into a new document.
<HTML>
<BODY>
This is a server ASP Demo.
It calculates the number of days until the end of the year.
<BR>
<BR>

<%
Dim iTargetYear, dTargetDate, iDateDiff

iTargetYear=Year(Date())
dTargetDate=DateSerial(iTargetYear,12,31)
iDateDiff=DateDiff("d",Date(),dTargetDate)
Response.Write "Today's date is " & Date() & ".<BR>"
Response.Write iDateDiff & " more days to year end."

%>

</BODY>
</HTML>
• Save the file as C:\INETPUB\WWWROOT\SERVERDEMO.ASP.
• Launch Microsoft Internet Explorer and test the sample by browsing
http://localhost/SERVERDEMO.ASP. Allow the program to complete, dismissing the message box by
clicking the button marked “OK”.
• In IE, view the HTML source of the client program by selecting the Source menu item from the View
menu.
What information is available in the Source? Is the script code visible? Will the script run if the extension
of the file is changed to HTM?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

3. To combine server side and client side scripting:


• Launch NOTEPAD.EXE and insert the following code example into a new document.
<HTML>
<BODY>
This is a simple client/server Demo that calculates the number of days
until the end of the year.
<BR>
<BR>
<%

Dim iTargetYear, dTargetDate, iDateDiff

iTargetYear=Year(Date())
dTargetDate=DateSerial(iTargetYear,12,31)
iDateDiff=DateDiff("d",Date(),dTargetDate)

%>

<Script Language="VBScript">
<!--

Sub Window_OnLoad
MsgBox "Today's date is <%=Date()%>."
MsgBox "<%=iDateDiff%> more days 'til year end."
End Sub

-->
</Script>

</BODY>
</HTML>

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Save the file as C:\INETPUB\WWWROOT\HYBRID.ASP.


• Launch Microsoft Internet Explorer and test the sample by browsing http://localhost/HYBRID.ASP.
Allow the program to complete, dismissing the message box by clicking the button marked “OK”.
• In IE, view the HTML source of the client program by selecting the Source menu item from the View
menu.
What information is available in the Source? Is the client side script visible? Is the server side (the
formulas) visible?

Lab 2: Administrating IIS 4.0

Objectives

What You Will Learn


After completing this lab, you will be able to:
• Configure common application settings using the Microsoft Management Console and IIS 4.0 property
sheets.
• Assign permissions to the IUSR_* account to allow proper access to ASP.

Related Topics Covered in this Lab


Recommended Reading

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Before You Begin


Prerequisites

Lab Setup
Copy all files from the student lab disk to a folder called LABS, located in the root directory of your C:
drive.

Estimated time to complete this lab: 45 minutes


For More Information
The Windows NT 4.0 Option Pack Documentation contains detailed information about setting up and
administrating IIS 4.0. It includes topics on: Web and FTP Sites; Configuring Applications; Security;
Logging; Performance Tuning.
This information can be found in the contents under:
Windows NT 4.0 Option Pack Product Documentation
Microsoft Internet Information Server (IIS)
Server Administration

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 1
Configuring Applications
In this exercise, you will create a new virtual directory that will be used throughout later exercises. You will
examine settings available through IIS 4.0 Property sheets and configure the new virtual directory as an
isolated application.
4. To launch Microsoft Internet Service Manager
• From the Start Menu, open the Programs group.
• Open the Windows NT 4.0 Option Pack group in the Programs group.
• Open the Microsoft Internet Information Server in the Windows NT 4.0 Option Pack.
• Select Internet Service Manager.
• Click on the button labeled “Close” to dismiss the Tip of the Day dialog.
5. To create a new virtual directory:
• In MMC’s scope pane (the left most window pane), navigate to Default Web Site as shown below.

• From the Action menu, select New and choose Virtual Directory from the submenu. This should launch
the New Virtual Directory Wizard.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step through the wizard using the Next button, providing the following information as shown in each of
the following screen shots:

Enter the alias used to access this virtual directory:

Enter the physical path containing the content:

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Grant the following access permissions to the virtual directory:

• Click the Finish button to complete the creation of the new Virtual directory.
Internet Service Manager should automatically mark the new Virtual Directory as an application.
• To test the new virtual directory, launch Microsoft Internet Explorer and browse
HTTP://LocalHost/Labs/Default.ASP.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 2
Using Various Authentication Methods
In this exercise, you will create a new NT user account that will provide restricted access to the web site
and restrict anonymous access. Additionally, you will determine the NT user account used by IIS 4.0 as the
default anonymous user account.
43192.To create a new user account under NT:
• From Window NT’s Start menu, open the Programs group.
• Open the Administrative Tools (Common) group in the Programs group.
• Select User Manager for Domains.
• From the User menu, select the “New User…” menu item.
• Fill in the New User dialog as shown below. Be sure to remove any checks in the checkboxes for
Password options and Account disabled.

Note: The password will actually show up as a series of asterisks(*) for security purposes.
• Click the button labeled “Add”.
• Click the button labeled “Close”.
• From the User menu, select the Exit menu item.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

43193.To secure the web site:


• Launch Internet Service Manager.
• In the scope pane, select the Default Web site for the local machine.
• From the Action menu, select Properties.
• Switch to the Directory Security tab in the Default Web Site Properties dialog.

• Click the edit button located in the Anonymous Access and Authentication Control section. This will
display the Authentication Methods dialog.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Clear and set the options for the authentication methods as shown in the image below. Ensure that only
Basic Authentication is enabled.
Note: When enabling the Basic Authentication option you will receive a message from Internet Service
Manager in a dialog. Read the warning, then dismiss this dialog box by clicking the button labeled "OK".

• Click the button labeled “OK” to dismiss the Authentication Methods dialog.
• Click the button labeled “OK” to dismiss the Web Site property sheet.
If you receive an "Inheritance Override" dialog asking which child nodes should inherit the authentication
method, click the button labeled "OK".
• Test the authentication method by browsing HTTP://LocalHost from within Microsoft Internet Explorer.
(If necessary, launch Internet Explorer.)
• When prompted for authentication the first time, click the button marked “Cancel” to bypass the login to
the web page.
What is the browser’s response?
• Refresh the web page using the toolbutton marked “Refresh”. When prompted for authentication, type
“BasicUser” as the User Name and “password” as the Password. Do not type the quotes for either User
Name or Password. Click the button marked “OK” to accept the user name and password.
Is access granted to the web site?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

43194.To restore access to the web site:


• Switch to Internet Service Manager.
• In the scope pane, select the Default Web site for the local machine.
• From the Action menu, select Properties.
• Switch to the Directory Security tab in the Default Web Site Properties dialog.
• Click the edit button located in the Anonymous Access and Authentication Control section. This will
display the Authentication Methods dialog.
• Enable the “Allow Anonymous Access” option and disable the Basic Authentication option.
• When “Allow Anonymous Access” is enabled, click the topmost button labeled “Edit”, that lies next to
the text “Account used for Anonymous Access:”
What NT User Account is IIS using for anonymous access?
• Click the button labeled “OK” to dismiss the Anonymous User Account dialog.
• Click the button labeled “OK” to dismiss the Authentication Methods dialog.
• Click the button labeled “OK” to dismiss the Default Web Site Properties dialog.
If you receive an "Inheritance Override" dialog asking which child nodes should inherit the authentication
method, click the button labeled "OK".
• Switch to Microsoft Internet Explorer. Browse the URL http://localhost (If it’s still the current page in the
browser, simply click on the toolbutton marked “Refresh”.)
Are you prompted for a user name and password?

Lab 3: Tools and Debugging

Objectives

What You Will Learn


After completing this lab, you will be able to:
• Create simple applications using Microsoft Visual Interdev.
• Debug ASP scripts using the Microsoft Script Debugger.

Recommended Reading

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Before You Begin


Prerequisites
To complete the exercises in this lab, it is necessary to have Microsoft Visual Interdev and Microsoft Script
Debugger installed on your local machine.
Estimated time to complete this lab: 30 minutes
For More Information
Visual Interdev Online Product Documentation "User Guide"; Overview section

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 1
Creating a Guest Book with Visual Interdev
In this exercise, you will create a guest book application using Visual Interdev. For the guest book to
function properly, you will need to create a new project in Visual Interdev, provide access to a data source
used to hold the guest information, and run the data form wizard to create the forms, HTML and ASP script
that provides access to the guest book information.
43195.To create a new project:
• From the File menu, select “New…”.

• File New dialog box:


• Switch to the Projects tab and select “Web Project Wizard.
• Type the name WebApp into the Project name text box.
• Click the button labeled “OK”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 1 of 2 dialog box:


• In the Server Name text box, type “Localhost”.

• Click the button labeled “Next”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 2 of 2 dialog box:


• Accept the defaults


• Click the button labeled “Finish”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

43196.To add a data connection:


• From the Project menu, select “Add to Project”, then select “Data Connection”.


• SelectSwitch to the Machine Data Source tab.
• Select the data source “AdvWorks” and click on the button labeled “OK”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

43197.To create the data forms:


• From the File menu, select “New…”.

• File New dialog box:


Switch to the File Wizards tab.
• Type “GuestBook” in the File name text box.
• Click the button labeled “OK”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 1 of 7 dialog box:


• Select DataConn from the dropdown as the database connection to use.
• Type “Guest Book Application” in the text box provided for the title that appears at the top of the form.


• Click on the button labeled “Next”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 2 of 7 dialog box:


• Choose Table from the listbox provided as the object to use for your form.


• Click on the button labeled “Next”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 3 of 7 dialog box:


• Choose Customers from the Table/View dropdown.
• Click the button labeled “>>” to move all fields from the Available Fields listbox over to the Select Fields
listbox.


• Click on the button labeled “Next”

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 4 of 7 dialog box:


• Examine the options available within this dialog.
• Accept the defaults in the dialog.

What functionality does step 4 of the wizard provide?


• Click on the button labeled “Next”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 5 of 7 dialog box:


• Accept the defaults in the dialog.


• Click on the button labeled “Next”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 6 of 7 dialog box:


• Accept the defaults in the dialog.


• Click on the button labeled “Next”.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Step 7 of 7 dialog box:


• Heave a sigh of relief, since there are no more dialogs.

• Click on the button labeled “Finish”.


How many ASP files have been created?
• Test the application by browsing the URL HTTP://LocalHost/WebApp/GuestBookForm.ASP.
Create a new record by clicking the button marked "New", filling in the fields, then clicking on the button
marked "Insert" to add the record.
Experiment and see what the other buttons in the forms do.

If Time Permits
Using Visual Interdev Wizards
Data Connections provide access to external data sources. Through a data connection, you can add, delete
or modify values in the underlying data. Additionally, you can create database diagrams displaying
relationships between tables, view stored procedures, create new objects and edit object properties. Take
some time to explore the Data View tab of the workspace. This tab is available anytime a data connection
exists in the current workspace.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 2
Debugging ActiveX Server Pages
In this exercise, you will use the Script Debugger to trouble script errors.
In order to use the script debugger with IIS 4.0, it is necessary to enable server side script debugging within
Internet Service Manager.
• Open Microsoft Internet Explorer and browse the URL HTTP://LocalHost/Labs/Lab3/Broken.ASP. It
should display an error message within the browser.
43352.To enable server side debugging:
• Launch Internet Service Manager.
• Display the property sheet for the Lab3 folder found in the Labs application under the default web site.
Create an application using Lab3 as the application root.
• Once Lab3 is marked as an application, the button marked "Configure" will be enabled in the property
sheets dialog. Click the Configure button to display the Application Configuration dialog.
• Switch to the App Debugging tab of the Application Configuration dialog

• Enable server-side script debugging by placing a check in the checkbox next to the label "Enable ASP
server-side script debugging".
• Click on the button labeled "OK" to dismiss the Application Configuration dialog.
• Click on the button labeled "OK" to dismiss the Property Sheets dialog.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

43353.To debug errors:


• Switch back to Microsoft Internet Explorer and browse the page
HTTP://LocalHost/Labs/Lab3/Broken.ASP.
What happens this time? Which line is the cursor on in the script debugger?
• Switch back to Microsoft Internet Explorer.
Note that the browser should be displaying the cursor as an hourglass.
• Switch back to Microsoft Script Debugger.
• From the Debug menu, select "Stop Debugging".
Has the cursor changed in Microsoft Internet Explorer?
• Close the copy of Broken.ASP that is open in Microsoft Script Debugger, leaving Script Debugger open.
• Launch NOTEPAD.EXE and open the file C:\Labs\Lab3\Broken.ASP.
• Correct the spelling of the variable iHour in line nine.
• Save the changes to the file.
• Switch back to Microsoft Internet Explorer and update the script page by clicking on the toolbutton
labeled "Refresh".
Does the script work? Does it display a message appropriate for the time of day shown by the computer's
system clock?
• Switch back to Microsoft Script Debugger.
• From the View menu, select "Running Documents".
• Expand the section listed as Microsoft Active Server Pages until you locate broken.asp

• Double click on broken.asp in the Running Documents window. This should open a read-only copy of the
newest version of broken.asp.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Locate the line that reads:


iHour=Hour(Time())
Place the cursor at the beginning of this line.
• From the Debug Menu, select "Toggle Breakpoint". This should cause the line to change appearance as
shown below, which indicates there is a breakpoint on the line.

• Switch to Microsoft Internet Explorer and browse the page HTTP://LocalHost/Labs/Lab3/Broken.ASP.


At this point, Microsoft Script Debugger should appear, with execution of Broken.ASP paused at the
breakpoint and a yellow arrow appears on the left side of our read-only file.
At which line does the yellow arrow point?
• From the Debug menu, select "Step Into".
Did the yellow arrow move to a different line?
• Repeat the previous step repeatedly until the yellow arrow points to the line containing the End If
statement.
Which path did the script run, "Good Morning" or "Good Afternoon"? Is this correct for the current time
of day?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Check the value of iHour:


• From the View menu, select "Command Window".
• Inside the Command Window, type
? iHour
• Press Enter.

What is the value of iHour on your machine?

It appears that Broken.ASP is printing the wrong message for the current time of day.

Can you fix Broken.ASP to correct this?

Lab 4: Built-in Objects

Objectives

What You Will Learn


After completing this lab, you will be able to:
• Access information supplied by the user through forms.
• Use cookies to track user information.
• Use the GLOBAL.ASA file to run special subroutines upon starting and quitting sessions.
• Use the Response object to send information back to the user’s browser.
• Add transaction processing using the <%@TRANSACTION=”REQUIRED”%> directive.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Related Topics Covered in this Lab


Recommended Reading
• Windows NT 4.0 Option Pack Documentation.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Before You Begin


Prerequisites
The exercises for this lab require that the C:\Labs folder and Labs virtual directory have been created
according to the directions in Lab 02 – Administration and Configuration.
Estimated time to complete this lab: 90 minutes
For More Information
The Windows NT 4.0 Option Pack Documentation contains several code examples and greater detail of the
built-in components included with IIS 4.0. You can locate this information by tracing the following path
from the content pane of the Windows NT 4.0 Option Pack Product Documentation.
Windows NT 4.0 Option Pack Product Documentation
Microsoft Internet Information Server (IIS)
Scripter’s Reference
Built-in ASP Objects

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 1
Using the Response and Request objects
In this exercise, you will use the Request object in order to retrieve HTTP server variables for the current
session. Server variables contain information about both the server and the browser, which can be used to
perform scripts when a server variable matches a value determined by the web developer.
In the first exercise, you will create a table that lists the server variables available with their associated
values, and add an image tag to the end of the file that determines which of two languages your browser
supports.
In the second half of the exercise, you will create an ASP page that will automatically redirect the browser
to a new web page dependent upon which language their browser is setup.
43354.To display the server variables in a web page:
• Launch NOTEPAD.EXE or Microsoft Visual Interdev and insert the script on the following page into a
new file:

d Support Training Microsoft ConfidentialOctober 2008


Appendices

<HTML>
<BODY>
<Table border=2>
<TR><TH>Name</TH><TH>Value</TH>
<%'Loop through all values and print in table
For each objsvar in Request.ServerVariables
Response.Write "<TR><TD>"
Response.Write objsvar
Response.Write "</TD><TD>"
Response.Write Request.ServerVariables(objsvar)
Response.Write "</TD></TR>"
Next%>
</TABLE>
<%'Check for English US or GB to see which flag to show
Language=Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
If Language="en-us" then
sFlagGIF="USA.GIF"
ElseIf Language="en-gb" Then
sFlagGif="UK.GIF"
Else
sFlagGIF=""
End If%>
Welcome!<BR>
<IMG SRC="../Images/<%=sFlagGif%>">
</BODY>
</HTML>
What are the two methods this code uses to send information back to the browser?
• Save the file as C:\Labs\Lab4\ServerVariables.ASP.
• Test the script by browsing HTTP://LocalHost/Labs/Lab4/ServerVariables.ASP.
Which flag is displayed at the bottom of the page?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

In Microsoft Internet Explorer, change the browser’s default language from US English to British
English:
43355.To change Explorer’s default language:
• Select “Internet Options” from the View menu in Internet Explorer.
• Click on the button labeled “Languages” found on the General tab.

• Remove any languages listed in the language listbox by highlighting the language and clicking the button
labeled “Remove”.
• Click the button labeled “Add”. Select the line that reads “English (British) [en-gb] and click on the
button labeled “OK”.
• Click the button labeled “OK” to dismiss the language dialog box.
• Click the button labeled “OK” to dismiss the Internet Options dialog box.
• Refresh the current page by clicking on the toolbutton labeled “Refresh”.
What flag is now displayed at the bottom of the page?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

43356.To redirect users to a specific page dependent upon a server variable:


• Launch NOTEPAD.EXE or Microsoft Visual Interdev and insert the following script into a new file:
<%Response.Buffer=True%>
<HTML>
<BODY>
Checking language...
<%
Language=Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
If Language="en-us" Then
NewSite="USEnglish.HTM"
ElseIf Language="en-gb" Then
NewSite="UKEnglish.HTM"
Else
NewSite="UnKnown.HTM"
End If

Response.Redirect NewSite
%>
</BODY>
</HTML>

• Save the file as C:\Labs\Lab4\LanguageStart.ASP.


• Test the script by browsing HTTP://LocalHost/Labs/Lab4/LanguageStart.ASP.
What is the URL displayed in the address bar of Microsoft Internet Explorer?
• Restore Explorer’s default language to English (United States)[en-us].
• Browse HTTP://LocalHost/Labs/Lab4/LanguageStart.ASP.
Do you wind up on the same page as you did the previous time?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 2
Retrieving values from forms using the Post
Method
In this exercise, you will use the post method to retrieve data from information supplied by a user by way
of a form.
10460.To create a user form:
• Open UsingPost.htm in either Notepad.exe or Visual Interdev. This file is found in the C:\Labs\Labs4
folder.
• Modify the <FORM> tag to match the <FORM> tag listed below:
<FORM method="Post" action="ProcessPost.asp">
• What does the action argument identify?
Can you identify the text boxes and their names?
• Save the changes for this file.
10461.To retrieve user data:
• Create a new text file using either NOTEPAD.EXE or ASP file using Visual Interdev.
• Insert the script listed below into the new text file.
<HTML>
<BODY>
<%
sResponse1=Request("text1") & "<BR>"
sResponse2=Server.HTMLEncode(Request("text2")) & "<BR>"

Response.Write "text1=" & sResponse1


Response.Write "text2=" & sResponse2

%>
</BODY>
</HTML>
• Save the new file as ProcessPost.asp in the C:\Labs\Lab4 folder.
• Test the application by browsing the following URL in Microsoft Internet Explorer:
HTTP://LocalHost/Labs/Lab4/UsingPost.HTM.
• In both Text1 and Text2 text boxes, type “<B>HELLO</B>” (without the quotes).
• Click the button labeled “OK”.
Did the new page display the contents of the two text boxes? How do the two values differ? How does the
script in ProcessPost.asp handle the two inputs differently that accounts for the difference?

If Time Permits
Retrieving Values from Forms
The examples from this exercise used two separate files to enter and display the information from the form.
Create an example that makes use of one form only (the action argument of the <FORM> tag calls itself).

d Support Training Microsoft ConfidentialOctober 2008


Appendices

So if the name of the script file is Test.asp, then the form tag will be <FORM ACTION=”TEST.ASP”
METHOD=”POST”>.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 3
Retrieving values from forms using the Get
Method
In this exercise, you will use the get method to retrieve data from information supplied by a user by way of
a form.
14552.To create a user form:
• Open UsingGet.htm in either Notepad.exe or Visual Interdev. This file is found in the C:\Labs\Labs4
folder.
• Modify the <FORM> tag to match the <FORM> tag listed below:
<FORM method="Get" action="ProcessGet.asp">
• What does the action argument identify?
Can you identify the text boxes and their names?
• Save the changes for this file.
14553.To retrieve user data:
• Create a new text file using either NOTEPAD.EXE or ASP file using Visual Interdev.
• Insert the script listed below into the new text file.
<HTML>
<BODY>
<%
sResponse1=Request.Querystring("text1")
sResponse2=Server.HTMLEncode(Request.QueryString("text2”))

Response.Write "text1=" & sResponse1 & "<BR>"


Response.Write "text2=" & sResponse2 & "<BR>"

%>
</BODY>
</HTML>
• Save the new file as ProcessGet.asp in the C:\Labs\Lab4 folder.
• Test the application by browsing the following URL in Microsoft Internet Explorer:
HTTP://LocalHost/Labs/Lab4/UsingGet.HTM.
• In both Text1 and Text2 text boxes, type “<B>HELLO</B>” (without the quotes).
• Click the button labeled “OK”.
Did the new page display the contents of the two text boxes? What appears with the URL in the address
bar of Microsoft Internet Explorer?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 4
Passing information between pages and
users
In this exercise, you will use the Session object and the Application object to pass information to multiple
web pages or between users using the same application.
• Launch NOTEPAD.EXE or Visual Interdev and create a new text file.
• Insert the following script into the new document:

<HTML>
<BODY>
<%
Application("Name")=Request.ServerVariables("REMOTE_ADDR")
Session("Name")=Request.ServerVariables("REMOTE_ADDR")
%>
Page One<BR>
Application=<%=Application("Name")%><BR>
Session=<%=Session("Name")%><BR>
<A HREF="PageTwo.ASP">Go To Next Page</A>
</BODY>
</HTML>

• Save the file as C:\Labs\Lab4\PageOne.ASP.

• Create another new text file and insert the following script:

d Support Training Microsoft ConfidentialOctober 2008


Appendices

<HTML>
<BODY>
Page Two<BR>
Application=<%=Application("Name")%><BR>
Session=<%=Session("Name")%><BR>
<%Session.Abandon
Response.Write "Session object closed (Session.Abandon)"%>
Session=<%=Session("Name")%><BR>
<A HREF="PageThree.ASP">Go To Next Page</A>
</BODY>
</HTML>

• Save the file as C:\Labs\Lab4\PageTwo.ASP.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Create a third text file and insert the following script:

<HTML>
<BODY>
Page Three<BR>
Application=<%=Application("Name")%><BR>
Session=<%=Session("Name")%><BR>
</BODY>
</HTML>

• Save the file as C:\Labs\Lab4\PageThree.ASP.


• Launch Microsoft Internet Explorer and test the application by browsing
HTTP://LocalHost/Labs/Lab4/PageOne.ASP.
What are the values of Application and Session?
• Follow the link to the next page.
Did Application and Session retain their values? What is the purpose of the Session.Abandon method?
• Follow the link to the next page.
Did Application and Session retain their values? What caused Session to lose its value?
• Have your neighbor browse your PageOne script (HTTP://machinename/Labs/Lab4/PageOne.ASP where
machinename is the computer name of your machine).
• Make note of the values in PageThree.ASP on your machine. Refresh the page in your browser using the
toolbutton marked “Refresh”.
What happened to the values when you refreshed your page? Why did the Application value change?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 5
Storing and retrieving values with cookies
In this exercise, you will use cookies as a semi-permanent storage medium. Cookie values are stored on the
browser using Response.Cookie, and are retrieved using Request.Cookie.
Cookies are often used to store user preferences across sessions or act as shopping carts for web stores.
• Launch NOTEPAD.EXE or Visual Interdev.
• In a new document, insert the following script:
<%'Response.Cookies require buffering
Response.Buffer=True%>

<HTML>
<BODY>
<%
Dim dLastVisited

‘Retrieve previous value of Cookie


dLastVisited=Request.Cookies("LastVisit")

‘Check if
If dLastVisited=Empty then
Response.Write "Welcome. This is your first visit"
Else
Response.Write "Welcome Back!<BR>"
Response.Write "You last visited on " & dLastVisited
End If

Response.Cookies("LastVisit")=Now()
Response.Cookies("LastVisit").Expires="December 31, 2000"

'The next line forces the session to quit


'proving that no session variable is involved
Session.Abandon
%>

</BODY>
</HTML>

d Support Training Microsoft ConfidentialOctober 2008


Appendices

• Save the file as C:\INETPUB\WWWROOT\COOKIES.ASP.


• Launch Microsoft Internet Explorer and test the script by browsing HTTP://LocalHost/COOKIES.ASP.
What is displayed in the browser?
• Shut down Internet Explorer, then repeat the previous step.
Did you receive a new message in the browser?

If Time Permits
Storing and retrieving values with cookies
Visual Interdev contains a sample application that incorporates a shopping application. Use Visual Interdev
to create the sample application project called Dos Perros and examine the shopping application.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 6
Using the GLOBAL.ASA file
In this exercise, you will create a GLOBAL.ASA file to track web usage.
The GLOBAL.ASA file provides a mechanism to run special procedures when application and sessions
either start or terminate. This provides the ability to run code for each new session on the web server.
This is an instructor led exercise, where the final script is generated by the class as a group.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 7
Using Transactions
In this exercise, you will add transaction processing to a web page. Transactions are typically used while
manipulating data within databases. If a web page that processes data abnormally ends, the database could
be left in an incomplete state. Transactions provide the mechanism to recover from these incomplete states.
While this example does not demonstrate transactions using databases, the next module covering databases
will provide a lab demonstrating the use of transactions with databases.

• Browse the page HTTP://LocalHost/Labs/Lab4/Transaction.asp.


It should return an error message.
• Open Transaction.asp in either Notepad or Visual Interdev.
Add the following VBScript to the end of the file:
<%
Sub OnTransactionAbort()
Response.Write "<BR><B>Error detected. Now recovering"
'Place error handling code here
End Sub

Sub OnTransactionCommit()
Response.Write "<BR><B>Transaction committed</B>"
End Sub
%>

• Save the changes to Transaction.asp.


• Browse the page HTTP://LocalHost/Labs/Lab4/Transaction.asp.
Is the output any different?
• Open Transaction.asp in either Notepad or Visual Interdev.
Add the following VBScript as the first line.
<%@Transaction=Required Language=”VBScript”%>
• Save the changes to Transaction.asp.
Browse the page HTTP://LocalHost/Labs/Lab4/Transaction.asp.
Is the output any different?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Lab 5: Installable Components

Objectives

What You Will Learn


After completing this lab, you will be able to:
• Send email from a web page using Collaboration Data Objects.
• Create a script that accesses external data using ADO.
• Maintain consistent data by using stored procedures and transactions within ADO.
• Use the Browser Capabilities component to identify client-side (browser) specifics.

Related Topics Covered in this Lab


Recommended Reading
• Windows NT 4.0 Option Pack Documentation.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Before You Begin


Prerequisites
This lab assumes you have performed a full install of IIS 4.0 to your local machine and the DSN AdvWorks
configured properly.

Lab Setup
This lab assumes you have copied the labs folder as instructed by the instructor and created a virtual
directory called LABS under IIS 4.0.

Estimated time to complete this lab: 75 minutes


For More Information
The Windows NT 4.0 Option Pack Documentation contains several code examples and greater detail of the
installable components included with IIS 4.0. You can locate this information by tracing the following path
from the content pane of the Windows NT 4.0 Option Pack Product Documentation.
Windows NT 4.0 Option Pack Product Documentation
Microsoft Internet Information Server (IIS)
Scripter’s Reference
Installable Components for ASP.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 1
Determining browser capabilities
In this exercise, you will use the Browser Capabilities object to determine what features a browser
supports.
• Launch Microsoft Internet Explorer and browse the URL HTTP://LocalHost/Labs/Lab5/Browser.ASP
What technologies are listed? What setting is shown for ActiveXControls?
• Using NOTEPAD.EXE, open the file C:\WINNT\SYSTEM32\INETSRV\BROWSCAP.INI.
• Locate the section labeled [IE 4.0] in the BROWSCAP.INI file. Find the line that reads
ActiveXControls=TRUE
in the [IE 4.0] section and change it to read
ActiveXControls=FALSE
• Save the changes to the file and close Notepad.
• Switch back to Microsoft Internet Explore and refresh the Browser.ASP page.
What setting is displayed for ActiveXControls now?
• Open NOTEPAD.EXE and insert the following script into a new file:
<%Response.Buffer=True%>
<HTML>
<BODY>
<%
Set BRW=CreateObject("MSWC.BrowserType")
If BRW.Tables=True Then
Response.Redirect "WithTables.HTM"
Else
Response.Redirect "WithoutTables.HTM"
End If
%>
</BODY>
</HTML>
• Save the file as C:\Labs\Lab5\Default.ASP.
• Look at the script and try to determine which page will appear if you browse
HTTP://LocalHost/Labs/Lab5/Default.ASP, based on the information you saw in BROWSER.ASP. (Do
not browse the page until you have made a guess.)
• Switch back to Microsoft Internet Explorer and browse HTTP://LocalHost/Labs/Lab5/Default.ASP.
Was the browser redirected to the page you predicted? What change to the BROWSCAP.INI file can you
make to change this behavior?

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 2
Accessing Data using ASP scripts
In this exercise, you will retrieve data from an Access database and display the records from a table within
the database on a web page, using ActiveX Data Objects. Web developers often use ADO to create guest
books, bulletin board systems or even order tracking tools.
To successfully create this web page, you must create a system data source within ODBC manager (you'll
use one already installed by IIS 4.0), instruct ASP to include special constants required for ADO and finally
retrieve the data using a recordset object.
1. To create the system data source:
• From the Start Menu, select Settings and launch Control Panel.
• Double-click on the ODBC icon in Control Panel.
• Switch to the System DSN tab.
• Verify that AdvWorks is listed as a Data Source in the System Data Sources list box.
2. To create the web page:
• Use NOTEPAD.EXE to open the file C:\Labs\Lab5\SIMPLEADO.ASP.
3. To include the special constants required by ADO:
• Type the following line into SIMPLEADO.ASP, immediately below the comment <!-- Place include here
-->.
<!--#include file = "adovbs.inc"-->
4. To create an ADO recordset object and access records from the database:
• Type the following script into SIMPLEADO.ASP immediately below the comment "'Place Code Here"
Dim objRS
Set objRS=Server.Createobject("ADODB.Recordset")
objRS.Open "Select * from Employees","DSN=ADVWorks;"
Do Until objRS.EOF
Response.Write objRS.Fields(1) & "&#32"
Response.Write objRS.Fields("LastName") & "<BR>"
objRS.MoveNext
Loop
objRS.Close
Set objRS=Nothing
• Save the changes to SIMPLEADO.ASP.
• Test SIMPLEADO.ASP by launching HTTP://LocalHost/Labs/SIMPLEADO.ASP in Internet Explorer.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 3
Adding New Data using ADO
In this exercise, you will create new records from data provided in a form by the user. In this example, you
will continue using the data source AdvWorks and the employees table from that database. To view whether
the code successfully added the new record from the form, this sample will call the ASP page from the
previous example to display all records from the employees table.
1. To setup the form to capture the user's data:
• Using Notepad, open the file CAPUSER.HTM, which is found in the LABS folder.
• Modify the line containing the <FORM> tag as follows:
<FORM Method="Post" Action="ADDUSER.ASP">
• Save the changes to CAPUSER.HTM.
2. To insert a new record:
• Use NOTEPAD.EXE to open the file ADDUSER.ASP, found in the LABS folder.
• In ADDUSER.ASP, immediately following the comment 'ADD SCRIPT HERE', add the script that
follows on the next page.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

On Error Resume Next

Set objConn = CreateObject("adodb.connection")


Set objCmd = CreateObject("adodb.command")

objConn.Open "DSN=AdvWorks"

Set objCmd.ActiveConnection = objConn

'Build SQL string to execute


sFirst="'" & Request("FName") & "'"
sLast="'" & Request("LName") & "'"
sSelect="Select " & sFirst & "," & sLast & ";"
sIns="Insert into Employees(FirstName,LastName) "

objCmd.CommandText = sIns & sSelect


objCmd.Execute

'Check for success


If objConn.Errors.Count=0 Then
Response.Write "Successfully added record"
Else
Response.Write "Could not add new record"
End If

objConn.Close
Set objConn=Nothing

• Save the changes to ADDUSER.ASP and test by browsing


HTTP://LOCALHOST/Labs/Lab5/CAPUSER.HTM in Microsoft Internet Explorer. Add yourself as a
new user and click the ADD button. If you receive a notice the record was added successfully, click the
VIEW ALL button on the result page to verify that your name has been added to the Employees table.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 4
Using Stored Procedures and Parameters
In this exercise, you will access stored procedures on a SQL Server to perform common tasks within the
database.
This exercise is a instructor led assignment which is created together by the class. The finished code can be
viewed in HTTP://LocalHost/Labs/Lab5/StoredProc.ASP.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 5
Using Transactions with ADO
In this exercise, you will create new records from data provided in a form by the user. In this example, you
will continue using the data source AdvWorks and the employees table from that database. To view whether
the code successfully added the new record from the form, this sample will call the ASP page from the
previous example to display all records from the employees table.
This exercise is a instructor led assignment which is created together by the class. The finished code can be
viewed in HTTP://LocalHost/Labs/Lab5/ADOTransact.ASP.

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Exercise 6
Sending Mail using an ASP script
In this exercise, you will create a web page that sends SMTP mail using information provided from a form.
This is a common request of web developers.
1. To capture user information in a form:
• Launch your favorite HTML editor and open EMAILFRM.HTM, found in the C:\Labs\Lab5 folder.
• Locate the <FORM> tag and modify the tag to read as follows.
• <FORM METHOD="Post" ACTION="SENDMAIL.ASP">
• Save the changes to EMAILFRM.HTM
2. To create a mail object
• Using Notepad or your favorite editor, open SENDMAIL.ASP, also found in the C:\Labs\Lab5 folder.
• Add the following VBScript to SENDMAIL.ASP. The VBScript should be placed immediately following
the comment "'ADD MAIL CODE HERE".
Dim objNewMail
Set objNewMail=Server.CreateObject("CDONTS.NewMail")
ObjNewMail.Send sFromName,sToName,sSubject,sMsg
Set objNewMail=Nothing
• Save the changes made to SENDMAIL.ASP
3. To test the application:
• Launch Internet Explorer and browse HTTP://LOCALHOST/LABS/LAB5/EMAILFRM.HTM.
• Fill out the information requested in the form, using valid email names for “From” and “To”.
• Click on the "Send" Button.

If Time Permits
Sending Mail using an ASP script
SENDMAIL.ASP is very simplistic, in that it does not perform any error trapping. Modify
SENDMAIL.ASP to check whether the user has filled in all fields from EMAILFRM.HTM, whether the
NewMail object is created successfully (use IsObject()), and the Send command succeeded (check
ERR.NUMBER). To incorporate error trapping, you will need to use the statement "On Error Resume
Next" at the prior to creating the NewMail object.

Appendix A - Version History of VBScript

The following table lists the version of Microsoft Visual Basic Scripting Edition implemented by host
applications.
VBScript VBScript VBScript
Host
Version 1.0 Version 2.0 Version 3.0
Microsoft Internet Explorer 3.0 

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Microsoft Internet Information Server 3.0 


Microsoft Internet Explorer 4.0 
Microsoft Internet Information Server 4.0 
Microsoft Windows Scripting Host 1.0 
Microsoft Outlook 98 
The following pages contains a listing of features specific to each version of VBScript, sorted by type and
feature name alphabetically.
For a complete listing of VBScript keywords, or detailed information on a specific keyword, please refer to
the Windows NT 4.0 Option Pack Product documentation in the following section:

Windows NT 4.0 Option Pack Product Documentation


Microsoft Internet Information Server (IIS)
Scripter’s Reference
VBScript Language Reference

d Support Training Microsoft ConfidentialOctober 2008


Appendices

t 1.0 Features

Functions

Abs IsEmpty
Asc IsNull
Atn IsNumeric
CBool IsObject
CByte LBound
CCur
CDate
CDbl
Chr
CInt
Cos
CSng
CStr
Date
DateSerial
DateValue
Day
Exp
Fix
Hex
Hour
InputBox
InStr
Int
IsArray
IsDate

d Support Training Microsoft ConfidentialOctober 2008


Appendices

LCase Oct Tan


Left Right Time
Len Rnd TimeSerial
Log RTrim TimeValue
LTrim Second Trim
Mid Sgn UBound
Minute Sin UCase
Month Space VarType
MsgBox Sqr Weekday
Now StrComp Year

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Methods

Clear Raise

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Objects

Error

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Properties

Description Source
Number

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Statements

Call Null
Dim On Error
Do...Loop Option Explicit
Empty Randomize
Erase ReDim
Exit Rem
False Select Case
For...Next Set
Function Sub
If...Then...Else True
Nothing While...Wend

VBScript 2.0 Features

Constants

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Color Miscellaneous
Comparison MsgBox
Date and Time String
Date Format VarType
File Input/Output

Functions

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Array LoadPicture
CreateObject MonthName
DateAdd Replace
DateDiff RGB
DatePart Round
Filter ScriptEngine
FormatCurrency ScriptEngineBuildVersion
FormatDateTime ScriptEngineMajorVersion
FormatNumber ScriptEngineMinorVersion
FormatPercent Split
GetObject StrReverse
InstrRev TypeName
Join WeekdayName

Methods

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Add ReadLine
Close Remove
CreateTextFile RemoveAll
Exists Skip
Items SkipLine
Keys Write
OpenTextFile WriteBlankLines
Read WriteLine
ReadAll

Objects

Dictionary TextStream
FileSystemObject

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Properties

AtEndOfLine HelpContext
AtEndOfStream HelpFile
Column Item
CompareMode Key
Count Line

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Statements

Const Private
For Each...Next Public

d Support Training Microsoft ConfidentialOctober 2008


Appendices

VBScript 3.0 Features

Collections

Drives Folders
Files

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Constants

DriveType SpecialFolder
File Attribute

d Support Training Microsoft ConfidentialOctober 2008


Appendices

Methods

d Support Training Microsoft ConfidentialOctober 2008


Appendices

AddFolders
BuildPath
Copy
CopyFile
CopyFolder
CreateFolder
Delete
DeleteFile
DeleteFolder
DriveExists
FileExists
FolderExists
GetAbsolutePathName
GetBaseName

d Support Training Microsoft ConfidentialOctober 2008


Appendices

GetDrive
GetDriveName
GetExtensionName
GetFile
GetFileName
GetFolder
GetParentFolderName
GetSpecialFolder
GetTempName
Move
MoveFile
MoveFolder
OpenAsTextStream

Objects

Drive Folder
File

Properties
d Support Training Microsoft ConfidentialOctober 2008
Properties 74

and Support Training Microsoft Confidential October 2008


Properties 75

Attributes
AvailableSpace
DateCreated
DateLastAccessed
DateLastModified
Drive
DriveLetter
Drives
DriveType
Files
FileSystem
FreeSpace
IsReady
IsRootFolder

and Support Training Microsoft Confidential October 2008


Properties 76

Name
ParentFolder
Path
RootFolder
SerialNumber
ShareName
ShortName
ShortPath
Size
SubFolders
TotalSize
Type
VolumeName

and Support Training Microsoft Confidential October 2008


Properties 77

Microsoft® Visual Basic® Scripting Edition

Visual Basic for


Applications Features not
in VBScript
Category Omitted Feature/Keyword
Array Handling Option Base
Declaring arrays with lower bound <> 0
Collection Add, Count, Item, Remove
Access to collections using ! character (e.g.,
MyCollection!Foo)
Conditional #Const
Compilation #If...Then...#Else
Control Flow DoEvents
GoSub...Return, GoTo
On Error GoTo
On...GoSub, On...GoTo
Line numbers, Line labels
With...End With
Conversion CVar, CVDate
Str, Val
Data Types All intrinsic data types except Variant
Type...End Type
Date/Time Date statement, Time statement
Timer
DDE LinkExecute, LinkPoke, LinkRequest, LinkSend
Debugging Debug.Print
End, Stop
Declaration Declare (for declaring DLLs)
New
Optional
ParamArray
Property Get, Property Let, Property Set
Static
Error Handling Erl
Error
On Error...Resume
Resume, Resume Next
File Input/Output All traditional Basic file I/O
Financial All financial functions
Object Manipulation TypeOf
Objects Clipboard
Collection
Operators Like
Options Deftype
Option Base
Option Compare
Option Private Module
Category Omitted Feature/Keyword
Select Case Expressions containing Is keyword or any comparison
operators

and Support Training Microsoft Confidential October 2008


Properties 78

© 1997 Microsoft Corporation. All rights reserved.

Microsoft® Visual Basic® Scripting Edition Language Reference


VBScript Features not in
Visual Basic for
Applications
Contents

Category Feature/Keyword
Formatting strings FormatCurrency
FormatDateTime
FormatNumber
FormatPercent
MonthName
WeekdayName
Intrinsic constants vbGeneralDate
vbLongDate
vbLongTime
vbShortDate
vbLongDate
vbTristateFalse
vbTristateMixed
vbTristateTrue
vbTristateUseDefault
Objects Dictionary
FileSystemObject
TextStream
Rounding Round
Strings Filter
InstrRev
Join
Replace
Split
StrReverse
Script Engine Identification ScriptEngine
ScriptEngineBuildVersion
ScriptEngineMajorVersion
ScriptEngineMinorVersion

© 1997 Microsoft Corporation. All rights reserved.

and Support Training Microsoft Confidential October 2008