Showing posts with label ASP Tutorial. Show all posts
Showing posts with label ASP Tutorial. Show all posts

ASP Variables

Lifetime of Variables

A variable declared outside a procedure can be accessed and changed by any script in the ASP file.

A variable is used to store information.

If the variable is declared outside a procedure it can be changed by any script in the ASP file. If the variable is declared inside a procedure, it is created and destroyed every time the procedure is executed.


A variable declared inside a procedure is created and destroyed every time the procedure is executed. No scripts outside the procedure can access or change the variable.

To declare variables accessible to more than one ASP file, declare them as session variables or application variables.
Session Variables

Session variables are used to store information about ONE single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences.
Application Variables

Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in a specific application.

Run ASP on Your PC

You can run ASP on your own PC without an external server. To do that, you must install Microsoft's Personal Web Server (PWS) or Internet Information Services (IIS) on your PC.
How to Run ASP on your own PC

You can run ASP on your own PC without an external server. To do that, you must install Microsoft's Personal Web Server (PWS) or Internet Information Services (IIS) on your PC.

If you are serious about using ASP, you should have at least Windows 98, Second Edition.

If you are really serious about using ASP, you should go for Windows 2000.
How to install PWS and run ASP on Windows 95

Personal Web Server (PWS) is not shipped with Windows 95 !!

To run ASP on Windows 95, you will have to download "Windows NT 4.0 Option Pack" from Microsoft.

Download the "Windows NT 4.0 Option Pack"
How to install PWS and run ASP on Windows NT

Personal Web Server (PWS) is not shipped with Windows NT !!

To run ASP on Windows NT, you will have to download "Windows NT 4.0 Option Pack" from Microsoft.

Download the "Windows NT 4.0 Option Pack"
How to install PWS and run ASP on Windows 98

1. Open the Add-ons folder on your Windows98 CD, find the PWS folder and run the setup.exe file.
2. An Inetpub folder will be created on your harddrive. Open it and find the wwwroot folder.
3. Create a new folder, like "MyWeb", under wwwroot.
4. Use a text editor to write some ASP code, save the file as "test1.asp" in the "MyWeb" folder.
5. Make sure your Web server is running - The installation program has added a new icon on your task bar (this is the PWS symbol). Click on the icon and press the Start button in the window that appears.
6. Open your browser and type in "http://localhost/MyWeb/test1.asp", to view your first ASP page.

How to install PWS and run ASP on Windows ME

Personal Web Server (PWS) is not included with Windows Me !!

Read article from Microsoft

A workaround!
How to install IIS and run ASP on Windows 2000

1. From your Start Button, go to Settings, and Control Panel
2. In the Control Panel window select Add/Remove Programs
3. In the Add/Remove window select Add/Remove Windows Components
4. In the Wizard window check Internet Information Services, click OK
5. An Inetpub folder will be created on your harddrive
6. Open the Inetpub folder, and find a folder named wwwroot
7. Create a new folder, like "MyWeb", under wwwroot.
8. Use a text editor to write some ASP code, save the file as "test1.asp" in the "MyWeb" folder
9. Make sure your Web server is running - The installation program has added a new icon on your task bar (this is the IIS symbol). Click on the icon and press the Start button in the window that appears.
10. Open your browser and type in "http://localhost/MyWeb/test1.asp", to view your first ASP page

How to install IIS and run ASP on Windows XP Professional

Note: You cannot run ASP on Windows XP Home Edition.

1. Insert the Windows XP Professional CD-Rom into your CD-Rom Drive
2. From your Start Button, go to Settings, and Control Panel
3. In the Control Panel window select Add/Remove Programs
4. In the Add/Remove window select Add/Remove Windows Components
5. In the Wizard window check Internet Information Services, click OK
6. An Inetpub folder will be created on your harddrive
7. Open the Inetpub folder, and find a folder named wwwroot
8. Create a new folder, like "MyWeb", under wwwroot.
9. Use a text editor to write some ASP code, save the file as "test1.asp" in the "MyWeb" folder
10. Make sure your Web server is running - its status can be checked by going into the Control Panel, then Administrative Tools, and double-click the "IIS Manager" icon
11. Open your browser and type in "http://localhost/MyWeb/test1.asp", to view your first ASP page

How to install IIS and run ASP on Windows Server 2003 (Windows .NET Server)

1. When you start the Windows Server 2003, you should see the Manage Your Server wizard
2. If the wizard is not displayed, go to Administrative Tools, and select Manage Your Server
3. In the wizard, click Add or Remove a Role, click Next
4. Select Custom Configuration, click Next
5. Select Application Server role, click Next
6. Select Enable ASP.NET, click Next
7. Now, the wizard may ask for the Server 2003 CD. Insert the CD and let it run until it is finished, then click the Finish button
8. The wizard should now show the Application Server role installed
9. Click on Manage This Application Server to bring up the Application Server Management Console (MMC)
10. Expand the Internet Information Services (IIS) Manager, then expand your server, and then the Web Sites folder
11. You should see the Default Web Site, and it should not say (Stopped)
12. IIS is running!
13. In the Internet Information Services (IIS) Manager click on the Web Service Extensions folder
14. Here you will see that Active Server Pages are Prohibited (this is the default configuration of IIS 6)
15. Highlight Active Server Pages and click the Allow button
16. ASP is now active!

ASP Web Based Email Using Microsoft's CDONTS

If you are reading this page then I shall assume that you already know a little bit about ASP and running ASP applications.

The download to this tutorial has 4 working examples of Web Wiz Email Form's (CDONTS) which you can use to allow your web site visitors to send their comments or enquiries to your e-mail address or send e-mails to their own friends form your site.

However, I not going to go into how the form is written as it uses standard HTML and JavaScript to capture the users details. Instead I'm going to concentrate on the actual methods and properties the CDONTS NewMail object uses to format and then send the email.

CDONTS stands for 'Collaboration Data Objects for Windows NT Server' and as the name suggest it is for NT, sorry Win9x users you don't have this component. The CDONTS component is installed when you install IIS on NT4 and Windows 2000. Although the component will run on Windows XP, Microsoft have decided to remove the component from IIS 5.1 on Windows XP, so you will have to track down a copy of the cdonts.dll and register it on the IIS web server.

To use this component to send e-mail you also need the SMTP Server that ships with IIS 4 or 5 installed on the web server. The SMTP server is usually installed by default with the standard IIS installation.

First we need to create the variables that we are going to be using in this script.


<% 'Dimension variables Dim objCDOMail 'Holds the CDONTS NewMail Object Next we need to create an instance of the 'CDONTS NewMail' object on the server. 'Create the e-mail server object Set objCDOMail = Server.CreateObject("CDONTS.NewMail") Once the 'NewMail' object has been created on the server we can use various properties and methods of the 'NewMail' object to build the e-mail. First we are going to use the 'From' property to let the recipient of the e-mail know who the e-mail is from. If you leave this property out or do not have a properly format e-mail address the e-mail will fail. 'Who the e-mail is from objCDOMail.From = "myE-mailHere@myDomain.com" Now we need to place a string value representing the e-mail address of the person you want to receive the e-mail into the 'To' property of the 'NewMail' object. 'Who the e-mail is sent to objCDOMail.To = "theirEmail@theirDomain.com" The next property 'Cc' holds the e-mail address of the people you wish to receive Carbon Copies of the e-mail. You can place one or more recipient e-mail addresses separated by either a comma (,) or a semicolon (;). Make sure all the e-mail address are properly formatted or the e-mail will fail. This property can be left out if you don't want any carbon copies of the e-mail sent. 'Who the carbon copies are sent to objCDOMail.Cc = "myFriend1@theirDomain.com;myFriend2@anotherDomain.com" The 'Bcc' property holds the e-mail address of the people you wish to receive Blind Copies of the e-mail. The formatting of the e-mail addresses is the same as for the 'Cc' property above. Again if you don't want to send any blind copies of the message you can leave this property out. 'Who the blind copies are sent to objCDOMail.Bcc = "myFriend1@theirDomain.com;myFriend2@anotherDomain.com" In the next line we use the 'Subject' property to set the subject of the e-mail. 'Set the subject of the e-mail objCDOMail.Subject = "Enquiry sent from my web site" As well as sending plain text e-mail's you can also format the body of the e-mail using HTML. The default is Text but if you wish to format the e-mail using HTML then you will need to use the 'BodyFormat' property with the integer value of '0' for HTML or '1' for Text. If you leave this property out the e-mail will be sent as plain text format. 'Set the e-mail body format (0=HTML 1=Text) objCDOMail.BodyFormat = 0 If you wish to use HTML formatting in the e-mail, as well as setting the 'BodyFormat' property above to HTML, you will also need to set the 'MailFormat' property to MIME. Again this property uses and integer value of '0' for MIME and '1' for Text. The default is text so if your e-mail is text only you can leave this property out. 'Set the mail format (0=MIME 1=Text) objCDOMail.MailFormat = 0 The next property were covering is the 'Body' property. This property holds the main part of the e-mail with the message you are sending. If you have set the 'BodyFormat' property to HTML and the 'MailFormat' to MIME then you can use HTML to format your e-mail message. 'eg.

Hello


This is my e-mail in HTML format'.

If you want to send the e-mail as text then you can just enter text instead. 'eg. Hello This is my e-mail in Text format'.


'Set the main body of the e-mail
objCDOMail.Body = "

Hello


This is my e-mail in HTML format"


The 'Importance' property tells the mail messaging system when to schedule delivery of the e-mail.

For this property there is 3 different integer values, 0 - Low, the e-mail will be sent during times of low system use, 1 - Normal, the message is sent at regular delivery times, 2 - High, the system will attempt to send the message immediately.

If this property is left out the default is Normal.


'Importance of the e-mail (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1


Once all the properties for the e-mail are set we can now send the e-mail using the 'Send' property.


'Send the e-mail
objCDOMail.Send


Finally once the e-mail has been sent we can close the server object releasing server resources.


'Close the server object
Set objCDOMail = Nothing
%>


There are other methods and properties of the 'NewMail CDONTS' object but to keep things simple I have tried to cover the most common properties needed to send an e-mail from your web site.

What Are Active Server Pages (ASP)?

Active Server Pages or ASP, as it is more commonly known, is a technology that enables you to make dynamic and interactive web pages.

ASP uses server-side scripting to dynamically produce web pages that are not affected by the type of browser the web site visitor is using.

The default scripting language used for writing ASP is VBScript, although you can use other scripting languages like JScript (Microsoft's version of JavaScript).

ASP pages have the extension .asp instead of .htm, when a page with the extension .asp is requested by a browser the web server knows to interpret any ASP contained within the web page before sending the HTML produced to the browser. This way all the ASP is run on the web server and no ASP will ever be passed to the web browser.

Any web pages containing ASP cannot be run by just simply opening the page in a web browser. The page must be requested through a web server that supports ASP, this is why ASP stands for Active Server Pages, no server, no active pages.

As ASP was first introduced by Microsoft on it's web server, Internet Information Services (IIS), that runs on Windows 2000/XP Pro/NT4, it is this web server that ASP pages usually run best on.

For those of you running Windows and wish to play around with ASP on your own system you will need to install Microsoft's Internet Information Services (IIS). Lucky IIS or its micro version Personal Web Server (PWS) comes free with Windows.

For Windows users you can find Internet Information Services (IIS) or Personal Web Server (PWS) in the following places: -

* Windows XP Pro/2003/2000 - IIS can be found in 'Add/Remove Programs' in the 'Control Panel'.
* Windows 98 - PWS can be found under 'add-ons' on the Windows 98 CD.
* Windows NT4/95 - You can get hold of IIS by downloading the NT4 Option Pack from Microsoft (don't be fooled by the name as it also runs on Windows 95).
* Windows ME - IIS and PWS are not supported on this operating system.
* Windows XP Home Edition - IIS and PWS are not supported on this operating system.

For those of you running other operating systems or web servers Sun produce a product called Chili!Soft ASP which enables ASP to be used on other web servers including, Apache, I-Planet, Zeus, Red Hat Secure Server, etc, using various operating systems including, Linux, Solaris, HP-UX, AIX, etc. You can find out more information on Sun Chilli!Soft ASP or download a trial version from,

ASP Tutorial





In our ASP tutorial you will learn about ASP, and how to execute scripts on your server.

You will see that ASP is a powerful tool for making dynamic and interactive Web pages.


What you should already know

Before you continue you should have some basic understanding of the following:

* HTML / XHTML
* A scripting language like JavaScript or VBScript

If you want to study these subjects first, find the tutorials on our Home page.
What is ASP?

* ASP stands for Active Server Pages
* ASP is a program that runs inside IIS
* IIS stands for Internet Information Services
* IIS comes as a free component with Windows 2000
* IIS is also a part of the Windows NT 4.0 Option Pack
* The Option Pack can be downloaded from Microsoft
* PWS is a smaller - but fully functional - version of IIS
* PWS can be found on your Windows 95/98 CD

ASP Compatibility

* ASP is a Microsoft Technology
* To run IIS you must have Windows NT 4.0 or later
* To run PWS you must have Windows 95 or later
* ChiliASP is a technology that runs ASP without Windows OS
* InstantASP is another technology that runs ASP without Windows

What is an ASP File?

* An ASP file is just the same as an HTML file
* An ASP file can contain text, HTML, XML, and scripts
* Scripts in an ASP file are executed on the server
* An ASP file has the file extension ".asp"

How Does ASP Differ from HTML?

* When a browser requests an HTML file, the server returns the file
* When a browser requests an ASP file, IIS passes the request to the ASP engine. The ASP engine reads the ASP file, line by line, and executes the scripts in the file. Finally, the ASP file is returned to the browser as plain HTML

What can ASP do for you?

* Dynamically edit, change or add any content of a Web page
* Respond to user queries or data submitted from HTML forms
* Access any data or databases and return the results to a browser
* Customize a Web page to make it more useful for individual users
* The advantages of using ASP instead of CGI and Perl, are those of simplicity and speed
* Provide security since your ASP code can not be viewed from the browser
* Clever ASP programming can minimize the network traffic

Important: Because the scripts are executed on the server, the browser that displays the ASP file does not need to support scripting at all!