scriptygoddess

30 Apr, 2003

ASP 101

Posted by: Jennifer In: Lessons learned

I'm currently in training this week for ASP (and finally we're done with "review" – very long story). While little of this is useful for blogs, I still wanted to document what I'm learning. Here are my notes from class:
(this is a VERY VERY long post.)

ASP Objects:
Request
Response
Session
Server
Applicaion

<%= is the same as &lt:% response.write("…
so these two are the same:
<% response.write(name) %>
<%=name%>

<script type="text/vbscript" runat="server">
That will force the script (which can also be javascript) to run on the server side

if code lines run long, use a "_" at the end of the line of code to indicate that the new line should be seen as a continuation of the current line.

hour(now)
Time function

Closest thing to an ASP manual: msdn.microsoft.com/scripting/

<@ language="vbscript" %>
(this is default (when page is .asp) but it's good practice to use this)

to include a file:
<!–#include file (or virtual) = "file.txt" –>

When form method is…
get – request.querystring (this gets values/variables from URL)
post – request.form

response.write("hello"+variable) or
response.write("hello"&variable)

request.querystring("variable")
-returns value of variable in url

dim
is used to declare variables

Request Object
5 collections:
client certificate
cookies
form
quesrystring
servervariables

shorthand – don't have to specify request ".form" or ".querystring" – can just do:
request("variable")

for each tempvarname in request.querystring (or)
for each tempvarname in request.form
response.write(tempvarname) 'this will write the current variable name
value = request.form(tempvarname)
response.write(value) 'this will write the value of the current variable name
next
(loops through all elements in the form)

request.servervariables("REMOTE_ADDR")
-will return users IP

to see everything in servervariables:
<% for each x in request.servervariables >%
<%= x %> : <%= request.servervariables(x) %>
<% next %>

Cookies
WRITE A COOKIE
response.cookies("thiscookiename") = "somevalue"
or
response.cookies("personalinfo")("name") = "Jennifer"
response.cookies("personalinfo")("url") = "http://www.scriptygoddess.com"

response.cookies("personalinfo").expires = #1/1/2004# 'date goes in between #

READ COOKIE
request.cookies("personalinfo")("name")
'returns value of cookie

Response object
1 collection: cookies
9 properties:
Buffer
cachecontrol
charset
expires
expiresabsolute
isclientconnected
PICS
status
8 methods:
appendtolog
binarywrite
clear
end
flush
redirect
write

response.redirect "http://www.awebpage.com"
(needs to be above first HTML tag)

Session (cookies)
(in php you have to start sessions with session_start() or something like that – asp session cookies autostart just by using them)

write a session cookie:
session("name") = "value"

read a session cookie:
session("name")

default is that session will stay alive for 20mins. or you can set the timeout by:
session.timeout
session.abandon (will force session to expire)
session.sessionid

Application (kinda like a server cookie)
sits on server. will die when server reboots.

application("totalvisitedthispage")

Server Object
1 property: scripttimeout
4 methods:
createobject
htmlencode
mappath
urlencode

(side note: to run asp on unix: chilisoft, or sun)

(I'll just keep adding to this one post as we go along)

7 Responses to "ASP 101"

1 | sean

May 1st, 2003 at 12:37 pm

Avatar

I hope you're they aren't just teaching you legacy ASP. If you're making the effort, go a little further to ASP.NET. Btw, Chilisoft rules on a *nix box. Pricey but worth it if you need to run ASP and don't want to run Windows.

2 | sean

May 1st, 2003 at 12:39 pm

Avatar

Hrm… looks like my english is all goofy this morning. Drop out that first you're. 8)

3 | dave

May 2nd, 2003 at 12:05 pm

Avatar

Most importantly never forgot to add

Option explicit (close off tags)

It'll save ya loads of time in the long run when debugging and also let you know when you mistype variables and stuff. Plus I find that it speeds up the site's code…

4 | Lee

May 3rd, 2003 at 10:54 am

Avatar

Anything you can do with PHP, you can do with ASP/ASP.net (or JSP for that matter). I use PHP for my blog because the hosting is cheap…

5 | php person

August 12th, 2003 at 6:59 pm

Avatar

One thing that I've found that I use frequently and can't duplicate in ASP are including files using variables as the file name.

I can do this in PHP

<?php

$inc_file = isset($_REQUEST["f"]) ? $_REQUEST["f"] : "default.html";

include_once($inc_file);

?>

6 | session

September 20th, 2003 at 4:18 am

Avatar

if you prefer, you can do asp using jscript
which is much nicer in syntax than vbscript

you can include files by doing:

var a;
a="subpage.js";
server.execute(a);

this iis,asp,jscript page does it using an array of page names

7 | chung

January 23rd, 2004 at 11:22 am

Avatar

If I can start over again, I'd think I should have learnt PHP in University as appose to ASP. The reason being is that Windows hosting in Australia cost an arm and a leg.

Another great resource is http://www.4guysfromrolla.com, one of the best ASP, ASP.NET tutorial sites out on the web.

Cheers

HostMania

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements