|
ASP was developed at Microsoft for use with their IIS web server package. ASP is a powerful tool for creating dynamic content, and for connecting to ODBC databases. All files with a .asp file extension will be processed by the server with the results being sent to the browser.
ASP can connect to databases, dynamically format the page, execute complex logic statements, and much more. You may use VBScript, JavaScript, PerlScript, and PythonScript within Active Server Pages, with VBScript set as the default scripting language. We recommend that you use VBScript as this should do everything you need and is the most commonly used.
This page lists some of the components installed and also gives some simple demonstration scripts and code snippets.
Please note that it is your responsibility to create and install your scripts and to debug them. If you have difficulty with your scripting, we can recommend a web developer that can create your scripts for you.
CDONTS CDONTS is a set of ASP components from Microsoft. CDONTS is most commonly used for sending email from a web page. The following is a demonstration script for sending email using JMail. You may use this within your own website and you are free to modify it in any way which suits you.
Copy the following code and save as cdonts.html
<html>
<head>
</head>
<body>
<form method="post" action="cdonts.asp">
Complete this form and click the submit-button. We will answer your questions as soon as possible.
<br><br>
Your Email Address<input type="text" size="25" name="email"><br>
<br>
Enter your question <br>
<textarea name="body" cols="40" rows="15" wrap="PHYSICAL"></textarea>
<br>
<input type="submit" value=" Submit ">
</form>
</body>
</html>
|
Copy the following code and save it as cdonts.asp. Remember to save it in the same directory as cdonts.html
<html>
<head>
</head>
<body>
<%
' Create new CDONTS object
set myEmail = Server.CreateObject("CDONTS.Newmail")
' Get information about the server and the form page that
' posted the information to this script
myReferer = Request.ServerVariables("HTTP_REFERER")
myServer = Replace(Request.ServerVariables("SERVER_NAME"), "www.", "")
myFrom = "me@" & myServer
myBody = Request.Form("body")
' Populate the CDONTS object
myEmail.to = Request.Form("email")
myEmail.from = myFrom
myEmail.Subject = "Email"
myEmail.body = myBody
' Check that the page that posted the information (the referer)
' is on the same server as this script. This will help prevent
' spammers using your scripts to send bulk mail.
myCompare = inStr(myReferer, myServer)
If myCompare > 0 Then
myEmail.Send
Response.Write "Email Sent"
Else
Response.Write "EMAIL NOT SENT"
End If
' Close CDONTS object
set myEmail = nothing
%>
</body>
</html>
|
JMail JMail is another email component which can be used as an alternative to CDONTS. The following is a demonstration script for sending email using JMail. You may use this within your own website and you are free to modify it in any way which suits you.
Copy the following code and save as form.html
<html>
<head>
</head>
<body>
<form method="post" action="SendMail.asp">
Complete this form and click the submit-button. We will answer your questions as soon as possible.
<br><br>
Your Name <input type="text" size="25" name="name"><br>
Your Email Address<input type="text" size="25" name="email"><br>
<br>
Enter your question <br>
<textarea name="body" cols="40" rows="15" wrap="PHYSICAL"></textarea>
<br>
<input type="submit" value=" Submit ">
</form>
</body>
</html>
|
Copy the following code and save it as sendmail.asp. Remember to save it in the same directory as form.html
<html>
<head>
</head>
<body>
<%
SenderName = Request.Form("name")
SenderEmail = Request.Form("email")
Subject = "Enquiry from website"
Body = Request.Form("body")
Recipient = "<youremailaddress>"
smtp_server_address="smtp.<yourdomain>"
Set myMail = Server.CreateObject("JMail.Message")
myMail.From = SenderEmail
myMail.Subject = Subject
myMail.AddRecipient Recipient
myMail.Body = SenderName & " asks: " & Body
myMail.Priority = 3
if not myMail.Send(smtp_server_address) then
' There was an error - print the error log
Response.Write ("Error:<br>" & myMail.log)
end if
%>
Your email has been sent <br>
</body>
</html>
|
ASP Upload Component The ASPUpload component is installed on the servers and can be used to upload files to your webspace directly from a web browser. You can find more information about ASP Upload as well as code samples at the Persits Software site at http://www.aspupload.com/
Database Connections There are a great many ways to connect to a database using ASP. The following are just a couple of common database connection strings that will work with Microsoft Access databases.
DSN-less database connection to a Microsoft Access database
strconn = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("databasename.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
|
Connecting to a Microsoft Access database with a DSN (Data Source Name) set up
set conn = server.createobject("adodb.connection")
conn.open "DataSourceName"
|
More Information You can find more about ASP together with a vast number of sample scripts at HotScripts.com or on the websites listed in our useful websites page.
|