Asp 2

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Asp 2 as PDF for free.

More details

  • Words: 7,319
  • Pages: 78
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

<%'Loop through all values and print in table For each objsvar in Request.ServerVariables Response.Write "" Next%>
NameValue
" Response.Write objsvar Response.Write "" Response.Write Request.ServerVariables(objsvar) Response.Write "
<%'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
tag to match the tag listed below: • 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. <% sResponse1=Request("text1") & "
" sResponse2=Server.HTMLEncode(Request("text2")) & "
" Response.Write "text1=" & sResponse1 Response.Write "text2=" & sResponse2 %> • 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 “HELLO” (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 tag calls itself). Microsoft ConfidentialOctober 2008

d Support Training

Appendices

So if the name of the script file is Test.asp, then the form tag will be .

Microsoft ConfidentialOctober 2008

d Support Training

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 tag to match the tag listed below: • 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. <% sResponse1=Request.Querystring("text1") sResponse2=Server.HTMLEncode(Request.QueryString("text2”)) Response.Write "text1=" & sResponse1 & "
" Response.Write "text2=" & sResponse2 & "
" %> • 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 “HELLO” (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?

Microsoft ConfidentialOctober 2008

d Support Training

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: <% Application("Name")=Request.ServerVariables("REMOTE_ADDR") Session("Name")=Request.ServerVariables("REMOTE_ADDR") %> Page One
Application=<%=Application("Name")%>
Session=<%=Session("Name")%>
Go To Next Page • Save the file as C:\Labs\Lab4\PageOne.ASP. • Create another new text file and insert the following script:

Microsoft ConfidentialOctober 2008

d Support Training

Appendices

Page Two
Application=<%=Application("Name")%>
Session=<%=Session("Name")%>
<%Session.Abandon Response.Write "Session object closed (Session.Abandon)"%> Session=<%=Session("Name")%>
Go To Next Page • Save the file as C:\Labs\Lab4\PageTwo.ASP.

Microsoft ConfidentialOctober 2008

d Support Training

Appendices

• Create a third text file and insert the following script: Page Three
Application=<%=Application("Name")%>
Session=<%=Session("Name")%>
• 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?

Microsoft ConfidentialOctober 2008

d Support Training

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%> <% 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!
" 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 %>

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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 "
Error detected. Now recovering" 'Place error handling code here End Sub Sub OnTransactionCommit() Response.Write "
Transaction committed" 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?

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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%> <% Set BRW=CreateObject("MSWC.BrowserType") If BRW.Tables=True Then Response.Redirect "WithTables.HTM" Else Response.Redirect "WithoutTables.HTM" End If %> • 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?

Microsoft ConfidentialOctober 2008

d Support Training

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 . 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) & " " Response.Write objRS.Fields("LastName") & "
" 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.

Microsoft ConfidentialOctober 2008

d Support Training

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 tag as follows: • 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.

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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.

Microsoft ConfidentialOctober 2008

d Support Training

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 tag and modify the tag to read as follows. • • 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. Host

VBScript Version 1.0

Microsoft Internet Explorer 3.0



Microsoft ConfidentialOctober 2008

VBScript Version 2.0

VBScript Version 3.0

d Support Training

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

Microsoft ConfidentialOctober 2008

Appendices

t 1.0 Features

d Support Training

Functions

Abs Asc Atn CBool CByte CCur CDate CDbl Chr CInt Cos CSng CStr Date DateSerial DateValue Day Exp Fix Hex Hour InputBox InStr Int IsArray IsDate Microsoft ConfidentialOctober 2008

IsEmpty IsNull IsNumeric IsObject LBound

d Support Training

Appendices

LCase Left Len Log LTrim Mid Minute Month MsgBox Now

Microsoft ConfidentialOctober 2008

Oct Right Rnd RTrim Second Sgn Sin Space Sqr StrComp

Tan Time TimeSerial TimeValue Trim UBound UCase VarType Weekday Year

d Support Training

Appendices

Methods

Clear

Microsoft ConfidentialOctober 2008

Raise

d Support Training

Appendices

Objects

Error

Microsoft ConfidentialOctober 2008

d Support Training

Appendices

Properties

Description Number

Microsoft ConfidentialOctober 2008

Source

d Support Training

Appendices

Statements

Call Dim Do...Loop Empty Erase Exit False For...Next Function If...Then...Else Nothing

VBScript 2.0 Features

Constants

Microsoft ConfidentialOctober 2008

Null On Error Option Explicit Randomize ReDim Rem Select Case Set Sub True While...Wend

d Support Training

Appendices

Color Comparison Date and Time Date Format File Input/Output

Functions

Microsoft ConfidentialOctober 2008

Miscellaneous MsgBox String VarType

d Support Training

Appendices

Array CreateObject DateAdd DateDiff DatePart Filter FormatCurrency FormatDateTime FormatNumber FormatPercent GetObject InstrRev Join

Methods

Microsoft ConfidentialOctober 2008

LoadPicture MonthName Replace RGB Round ScriptEngine ScriptEngineBuildVersion ScriptEngineMajorVersion ScriptEngineMinorVersion Split StrReverse TypeName WeekdayName

d Support Training

Appendices

Add Close CreateTextFile Exists Items Keys OpenTextFile Read ReadAll

ReadLine Remove RemoveAll Skip SkipLine Write WriteBlankLines WriteLine

Dictionary FileSystemObject

TextStream

Objects

Microsoft ConfidentialOctober 2008

d Support Training

Appendices

Properties

AtEndOfLine AtEndOfStream Column CompareMode Count

Microsoft ConfidentialOctober 2008

HelpContext HelpFile Item Key Line

d Support Training

Appendices

Statements

Const For Each...Next

Microsoft ConfidentialOctober 2008

Private Public

d Support Training

Appendices

VBScript 3.0 Features

Collections

Drives Files

Microsoft ConfidentialOctober 2008

Folders

d Support Training

Appendices

Constants

DriveType File Attribute

Microsoft ConfidentialOctober 2008

SpecialFolder

d Support Training

Appendices

Methods

Microsoft ConfidentialOctober 2008

d Support Training

Appendices

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

Microsoft ConfidentialOctober 2008

d Support Training

Appendices

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

Objects

Drive File

Properties Microsoft ConfidentialOctober 2008

Folder

and Support Training

Properties

Microsoft Confidential

74

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

and Support Training

Category Array Handling

Omitted Feature/Keyword 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 Microsoft Confidential

October 2008

Properties

78

© 1997 Microsoft Corporation. All rights reserved. Microsoft® Visual Basic® Scripting Edition

VBScript Features not in Visual Basic for Applications

Language Reference

Contents Category Formatting strings

Intrinsic constants

Objects Rounding Strings

Script Engine Identification

Feature/Keyword FormatCurrency FormatDateTime FormatNumber FormatPercent MonthName WeekdayName vbGeneralDate vbLongDate vbLongTime vbShortDate vbLongDate vbTristateFalse vbTristateMixed vbTristateTrue vbTristateUseDefault Dictionary FileSystemObject TextStream Round Filter InstrRev Join Replace Split StrReverse ScriptEngine ScriptEngineBuildVersion ScriptEngineMajorVersion ScriptEngineMinorVersion

© 1997 Microsoft Corporation. All rights reserved.

and Support Training

Microsoft Confidential

October 2008

Related Documents

Asp 2
October 2019 29
Asp 2
October 2019 27
Asp 2
November 2019 25
Asp
November 2019 69
Asp
June 2020 51
Asp
November 2019 61