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 <:% 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)