ASP (Active Server Page)
Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society

Static Web Pages
Page content doesn¶t change. 

Same every time it is delivered by the web server Pages we have created so far

IT Scientific Society - December 2006


Static Web Page Delivery
Web Server

Author writes HTML


Web server locates .htm file


HTML stream returned to browser

Client requests page

Browser processes page

IT Scientific Society - December 2006



Dynamic Web Pages
Created on the fly based on user actions or current conditions. Allows the page to be customized to the user and the situation.

IT Scientific Society - December 2006


Why Dynamic Web Pages?
Interactivity with user 

Personalize content to user
Greet user

Adapt to user input
Games, calculators, conversion utilities

1. 2. 3.   

Provide corporate information Access to physical products Access to services User sessions that connect visits to multiple pages Connections to databases on the server Pages created ³on the fly´ for customer

IT Scientific Society - December 2006


finds page. displays it Advanced things can happen on one or both sides IT Scientific Society . processes it.December 2006 6 . Client-side Processing Computer processing can happen in two locations   Server: Accepts request. sends it Client: Gets HTML (or more?) from net.Server-side vs.

December 2006 Client 7 .Server-side Dynamic Page Delivery Web Server 1 Author writes instructions 3 4 Web server locates instructions file Web server processes instructions to create HTML 5 HTML stream returned to browser 2 Client requests page 6 Browser processes page IT Scientific Society .

Client-side Web Page Delivery Web Server 1 Author writes instructions 3 4 Web server locates instructions file HTML and script are returned to browser 5 2 Client requests page Web browser processes script to create HTML 6 Client IT Scientific Society .December 2006 Browser displays HTML 8 .

VBScript Java applets XML CGI Active Server Pages (ASP) PHP Java Server Pages (JSP) ColdFusion Server-Side Alternatives:      IT Scientific Society .Many Technology Choices Client-Side Technologies:    Scripting languages: JavaScript.December 2006 9 .

etc.December 2006 10 .Server-side scripts or Client-side scripts? Server-side    Client-side      Processed by server Does not rely on browser support Provide browser with data that does not reside on client Script code not visible in page source Can Manage sessions (shopping baskets.) Database processing Processed by browser Does not depend on web server requirements Does not need to interact with server to create content processed by browser  Script code is viewable in page source IT Scientific Society .

Server.and Client-side Scripting Web Server 1 Author writes page code 3 4 Web server locates page file Web server asks script engines to process scripts & generate HTML 5 HTML stream passed back to server 6 2 Client requests page Browser processes client side scripts 7 Browser processes HTML & displays page Client IT Scientific Society .December 2006 11 .

IT Scientific Society . Microsoft Visual InterDev is the best tool for you.December 2006 12 .ASP ± Middleware for Windows platform ASP stands for Active Server Pages VBScript is the default scripting language for ASP If you are looking for some special software to write an ASP page.

ASP ± Middleware for Windows platform Active Server Page can include both client side and server side scripts. In an ASP page VBScript is usually used as the server side and Java Script as the client side scripting language IT Scientific Society .December 2006 13 .

XML. HTML.asp IT Scientific Society . and scripts Scripts in an ASP file are executed on the server An ASP file has the file extension *.What is an ASP file? An ASP file is just the same as an HTML file An ASP file can contain text.December 2006 14 .

response. ASP World.What is an ASP file? <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD><BODY> <% ' This will print to the browser the ' words Hello.write "Hello. ASP World!" %> </BODY></HTML> IT Scientific Society .December 2006 15 .

December 2006 16 .What can be done with ASP 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 IT Scientific Society .

removing all ASP script and replacing it with HTML text Client requests ASP File Client Server returns HTML text to client IT Scientific Society .December 2006 17 Taken from Mitchell & Atkinson (2000) .Client/Server Interaction for ASP Files Server Server locates the ASP file on the hard drive and parses it.

ASP World.Client/Server Interaction for ASP Files File On Server <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD><BODY> <% ' This will print to the browser the ' words Hello. ASP World!" %> </BODY></HTML> Result on Client <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD><BODY> Hello. response. ASP World! </BODY></HTML> IT Scientific Society .write "Hello.December 2006 18 .

but fully functional .0 or later To run PWS you must have Windows 95 or later IT Scientific Society .version of IIS To run IIS you must have Windows NT 4.December 2006 19 .ASP compatibility ASP is an engine/program built into Internet Information Server (IIS) / Personal Web Server (PWS) PWS is a smaller .

Installing IIS IT Scientific Society .December 2006 20 .

December 2006 21 .Running IIS IT Scientific Society .

IIS Environment IT Scientific Society .December 2006 22 .

IIS Default Folder IT Scientific Society .December 2006 23 .

0.asp http://127.asp IT Scientific Society .1/page.Opening an ASP File http://localhost/page.0.asp http://[Computer-name]/page.December 2006 24 .

What Does ASP Look Like in Action? IT Scientific Society .December 2006 25 .

Conn. 2001) and Symposium (May 24.uconn.edu/~wwwbiotc/99wkshp. For additional information</p> <ul> <li><a href="http://www.December 2006 26 .ucc. 2001) at the National Analytical Ultracentrifugation Facility.What Does ASP Look Like in Action? What HTML ³looks like´ <p>Analytical Ultracentrifugation Workshop (May 21-23.asp">Analytical Ultracentrifugation Workshop and Symposium Description and Registration (PDF Format)</a></li> </ul> IT Scientific Society .html" target="_blank"> National Analytical Ultracentrifugation Facility</a></li> <li><a href="naufworkshop. Storrs.

For additional information</p> <ul><li><a href="http://www.What Does ASP Look Like in Action? What the ³real code´ looks like* <% If Today < CDate("5/25/01") Then %> <p>Analytical Ultracentrifugation Workshop (May 21-23. 2001) and Symposium (May 24.asp">Analytical Ultracentrifugation Workshop and Symposium Description and Registration (PDF Format)</a></li> </ul> <% End If %> IT Scientific Society . 2001) at the National Analytical Ultracentrifugation Facility.December 2006 27 .edu/~wwwbiotc/99wkshp. Storrs. Conn.html" target="_blank">National Analytical Ultracentrifugation Facility</a></li> <li><a href="naufworkshop.uconn.ucc.

ASP Object Model ASP itself is not Object-Oriented.December 2006 28 . ASP can use objects but cannot define new objects Composed of   5 objects 5 components IT Scientific Society .

ASP Objects Request Response Server Application Session IT Scientific Society .December 2006 29 .

December 2006 30 .ASP Components Scripting Objects Component ADO (ActiveX Data Objects) Component Ad Rotator Component Browser Capabilities Component Content Linking Component IT Scientific Society .

certificate.December 2006 31 .QueryString (³fname´) %> IT Scientific Society . server variables Example <% Request.Request Can get input from query string or form Can get cookie information Can also get total bytes.

flush output Can redirect Example <% Response.December 2006 32 . write.Response Can send output to user through web page Can set cookie values Can set character set. expiration Can clear.Write ³message´ %> IT Scientific Society .

maintain user information or state in stateless HTTP protocol Client has an id number and expiration time from last request or expires Client can terminate or abandon causing Session object to be destroyed as well IT Scientific Society . Want to identify.Session Store user information during request and response and request and response«.December 2006 33 .

December 2006 34 .Application Information about entire website Global variables Example is a counter Lock and UnLock to access to update IT Scientific Society .

December 2006 35 .ServerVariable(REMOTE_ADDR) IT Scientific Society .Server Server related utility functions Script time out for running say a DB query Create an object like DB object Can enable URL encoding Example: Request.

December 2006 36 .connection´) Include statement for reuse of say login.QueryString(³fname´) %> <% Request (fname) %> Server. password IT Scientific Society .Write (³message´) %> <% = ³message´ %> <% = sStr1 %> & is concatenate operator <% Request.CreateObject(³ADODB.VBscript <% « %> open and close script area <% Response.

December 2006 37 . Else « end if Not case sensitive For statement For I = 1 to 8 statements Next While statement Wend Case statement IT Scientific Society .Logic If « then «.

Searching (strings) Math abs(number) Also. and example: Function add(a. Function can return a value. Date.b) add=a+b End Function IT Scientific Society . subroutines cannot.Functions Type casting like CStr(expression) Checking type. user defined function and subroutines.December 2006 38 .

Operators Concatenation operator is & (watch use of µ and ³ to build string with variables) + .December 2006 39 .* < > or and mod etc. = also = to print out IT Scientific Society .

Write("Hello World!") %> </body> </html> IT Scientific Society .December 2006 40 .write("Hello World!") %> </body> </html> JavaScript <%@ language="javascript" %> <html> <body> <% Response.ASP Syntax VBScript: <html> <body> <% response.

Variables <html> <body> <% dim name name=³Javan" response.write("My name is: " & name) %> </body> </html> IT Scientific Society .December 2006 41 .

Arrays <html> <body> <% Dim famname(6).December 2006 42 .write(famname(i) & "<br />") Next %> </body> </html> IT Scientific Society .i famname(1) = "Jan Egil" famname(2) = "Tove" famname(3) = "Hege" famname(4) = "Stale" famname(5) = "Kai Jim" famname(6) = "Borge" For i = 1 to 6 response.

December 2006 43 .Loops <html> <body> <% dim i for i=1 to 6 response.write("<h" & i & "> Header " & i & "</h" & i & ">") next %> </body> </html> IT Scientific Society .

write("Good Morning!") else response.December 2006 44 .write("<p>" & now() &´</p>´) If h<12 then response.write("Good day!") end if %> </body> </html> IT Scientific Society .Example (VB) <html> <body> <% dim h h=hour(now()) response.

Write("<p>³ + d + ³</p>´) if (h<12) { Response.getHours() Response.Example (JavaScipt) <%@ language="javascript" %> <html> <body> <% var d=new Date() var h=d.December 2006 45 .Write("Good day!") } %> </body> </html> IT Scientific Society .Write("Good Morning!") } else { Response.

December 2006 46 .write(num1*num2) end sub %> </head> <body> <p>Result: <%call vbproc(3.4)%></p> </body> </html> IT Scientific Society .Procedures (VB) <html> <head> <% sub vbproc(num1.num2) response.

num2) { Response.4)%></p> </body> </html> IT Scientific Society .Procedures (JavaScript) <%@ language="javascript" %> <html> <head> <% function jsproc(num1.December 2006 47 .Write(num1*num2) } %> </head> <body> <p>Result: <%jsproc(3.

asp"> First Name: <input type="text" name="fname"> <br /> Last Name: <input type="text" name="lname"> <br /><br /> <input type="submit" value="Submit"> </form> IT Scientific Society .Forms <form method="get" action="simpleform.December 2006 48 .

Sending Information over get method /simpleform.December 2006 49 .asp?fname=Morteza&lname=Javan IT Scientific Society .

write(request.write(" " & request.querystring("fname")) response.querystring("lname")) %> </body> IT Scientific Society .Process Information <body> Welcome <% response.December 2006 50 .

Cookies Create a Cookie: <% Response.Cookies("firstname") response.Cookies("firstname")="Alex" %> Retrieve a Cookie value: <% fname=Request.December 2006 51 .write("Firstname=" & fname) %> IT Scientific Society .

cookies("NumVisits") if numvisits="" then response.write("You have visited this Web page " & numvisits) if numvisits=1 then response.cookies("NumVisits")=numvisits+1 response.write("Welcome! This is the first time you are visiting this Web page.write " times before!" end if end if %> </body> </html> IT Scientific Society .write " time before!" else response.Expires=date+365 numvisits=request.December 2006 52 .Example of Cookies <html> <body> <% dim numvisits response.") else response.cookies("NumVisits").cookies("NumVisits")=1 response.

learnasp.com/pub/1/asp1.asp http://www.com/ http://www.asp?UR L=/library/en-us/dnasp/html/asptutorial.com http://msdn.w3schools.Online ASP Tutorials http://www.asp IT Scientific Society .December 2006 53 .vallin.com/ http://www.4guysfromrolla.com/library/default.15seconds.com/ http://www.microsoft.

Sign up to vote on this title
UsefulNot useful