Dino's ASP Page



This is simply a page to test ASP and learn how it works.

For now, it has some brief notes, but it will be improved as time goes by.

General Info about ASP

Active Server Pages (ASP) is a server-side scripting language developed by Microsoft. It is used to perform certain operations before the page's HTML loads, and can be used to generate HTML itself.

You can go into ASP mode using the special opening tag <%, and then use %> to close ASP mode and go back to HTML.

ASP is not a language on its own, but is based on other scripting languages such as VBScript and JavaScript. VBScript is the default language used, but you can change language as follows if you don't like it:

<%@ language="javascript"% >

ASP files must have the .asp extension. While the index file of a folder is normally named index.*, ASP index files are normally named default.asp.

Writing with ASP

Writing with ASP makes use of the response.write function:

<% response.write("YAAAAAAAAA!") %>

The word in brackets will be displayed on screen.

The ampersand (&) is the conjunction operator just like the dot (.) is in PHP. You can join multiple strings with it:

<% response.write("YAAAAAAAAA!" & "You " & "sure are ugly!") %>

If you want to quotes to be written, be sure to write quotes twice or they will end the string prematurely and cause errors:

<% response.write("He told me ""I'm dying!"" and breathed his last.") %>

<%=...> is equivalent to response.write:

<%= "Cool huh" & "!" %>

Whatever you write with ASP in the above methods will be written on one line in the page code (as you will see if you choose to View the Source). Line breaks (which are <br /> in XHTML) make use of the VBScript vbCrLf constant:

<% response.write("Hey" & vbCrLf & "you!") %>

Including with ASP

Including files with ASP makes use of an HTML comment, in which some special code is inserted:

<!--#include file="top.htm"-->

I have yet to figure out how to include files depending on the GET value in the address bar like in PHP because of this clumsy inclusion method that isn't from the ASP code. However, I have managed to make it write something depending on whether $_GET["page"] is set:

  if (request.querystring("page") = "") then
    response.write("not set")
  else response.write("is set")
  end if

ASP Form Handling

Imagine you have the following form:

<form name="form" action="submitted.asp" method="get">
Name: <input type="text" name="name" value="name"><br>
Surname: <input type="text" name="surname" value="surname"><br>
<input type="submit" value="Send it in!">

This form is made of two text fields asking for name and surname, and a submit button.

If the form has the GET method, use the request.querystring function. If it has the POST method, use the request.form function. With the get method, for example, it looks like this:

Your name is
response.write(request.querystring("name") & " and your surname is " & request.querystring("surname") & ".")

This neat little script will return the person's name and surname.

Simple Login Script

First we need a nice little form...

<form action="login2.asp" method="post">
<p>Name: <input type="text" name="name" /></p>
<p>Password: <input type="password" name="pass" /></p>
<p><input type="submit" name="submit" value="Login" /></p>

...then a script to see if the login is correct. If it is not, the intruder will get a sweet little message.


If request.form("pass") = "beep" AND request.form("name") = "admin" Then
   response.write("User successfully logged in.")
   response.write("Go away!")

End If

© Daniel D'Agostino 2003-2005
dandago at gmail.com