d Support Training
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
Microsoft ConfidentialOctober 2008
d Support Training
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
Microsoft ConfidentialOctober 2008
d Support Training
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. This is a simple VBScript Demo. It calculates the number of days until the end of the year. <Script Language="VBScript"> • 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).
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
2.
To create the server side script example:
• Launch NOTEPAD.EXE and insert the following code example into a new document. This is a server ASP Demo. It calculates the number of days until the end of the year.
<% Dim iTargetYear, dTargetDate, iDateDiff iTargetYear=Year(Date()) dTargetDate=DateSerial(iTargetYear,12,31) iDateDiff=DateDiff("d",Date(),dTargetDate) Response.Write "Today's date is " & Date() & ".
" Response.Write iDateDiff & " more days to year end." %> • 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?
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
3.
To combine server side and client side scripting:
• Launch NOTEPAD.EXE and insert the following code example into a new document. This is a simple client/server Demo that calculates the number of days until the end of the year.
<% Dim iTargetYear, dTargetDate, iDateDiff iTargetYear=Year(Date()) dTargetDate=DateSerial(iTargetYear,12,31) iDateDiff=DateDiff("d",Date(),dTargetDate) %> <Script Language="VBScript"> ." MsgBox "<%=iDateDiff%> more days 'til year end." End Sub -->
Microsoft ConfidentialOctober 2008
d Support Training
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 •
Microsoft ConfidentialOctober 2008
d Support Training
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
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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:
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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?
Microsoft ConfidentialOctober 2008
d Support Training
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 •
Microsoft ConfidentialOctober 2008
d Support Training
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
Microsoft ConfidentialOctober 2008
d Support Training
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”.
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
• Step 1 of 2 dialog box: • In the Server Name text box, type “Localhost”.
• Click the button labeled “Next”.
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
• Step 2 of 2 dialog box: • Accept the defaults
• • Click the button labeled “Finish”.
Microsoft ConfidentialOctober 2008
d Support Training
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”.
Microsoft ConfidentialOctober 2008
d Support Training
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”.
Microsoft ConfidentialOctober 2008
d Support Training
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”.
Microsoft ConfidentialOctober 2008
d Support Training
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”.
Microsoft ConfidentialOctober 2008
d Support Training
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”
Microsoft ConfidentialOctober 2008
d Support Training
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”.
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
• Step 5 of 7 dialog box: • Accept the defaults in the dialog.
• • Click on the button labeled “Next”.
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
• Step 6 of 7 dialog box: • Accept the defaults in the dialog.
• • Click on the button labeled “Next”.
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
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?
Microsoft ConfidentialOctober 2008
d Support Training
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.
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
Related Topics Covered in this Lab •
Recommended Reading • Windows NT 4.0 Option Pack Documentation.
Microsoft ConfidentialOctober 2008
d Support Training
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
Microsoft ConfidentialOctober 2008
d Support Training
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:
Microsoft ConfidentialOctober 2008
d Support Training
Appendices
Name | Value | <%'Loop through all values and print in table For each objsvar in Request.ServerVariables Response.Write "
---|
" Response.Write objsvar Response.Write " | " Response.Write Request.ServerVariables(objsvar) Response.Write " |
" Next%>
<%'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!
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?
Microsoft ConfidentialOctober 2008
d Support Training
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?
Microsoft ConfidentialOctober 2008
d Support Training
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%> 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 %> • 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?
Microsoft ConfidentialOctober 2008
d Support Training
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