Introduction to Active Server Pages ASP - PowerPoint PPT Presentation


PPT – Introduction to Active Server Pages ASP PowerPoint presentation | free to view - id: 5cba7-NmRmN


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Introduction to Active Server Pages ASP


Introduction to Active Server Pages (ASP) Marios Tziakouris. University of Cyprus. EPL602 ... Active Server Pages (ASP). Now version 3.0 ... – PowerPoint PPT presentation

Number of Views:9119
Avg rating:3.0/5.0
Slides: 60
Provided by: JeffreyA159


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Introduction to Active Server Pages ASP

Introduction to Active Server Pages (ASP)
  • Marios Tziakouris
  • University of Cyprus
  • EPL602
  • Fall 2004

  • What is ASP?
  • Compare and contrast ASP with standard HTML
  • Compare ASP to client-side and server-side
    scripting languages
  • ASP Crash Course
  • ASP Objects

Objectives (continued)
  • Connecting to databases
  • Tools you need to create ASP applications
  • Steps to start developing
  • Reference tools
  • Myths of ASP
  • Conclusions and Q A

What is ASP?
  • Active Server Pages (ASP). Now version 3.0
  • Microsoft Technology running on Internet
    Information Services (IIS)
  • Its not a language neither an application
    primarily it is a technology
  • A series of objects and components that are
    executed on the web server
  • Uses a suite of technologies that allows
    dynamically-generated content
  • Control of how content is generated from the
    server to the browsers

HTML Page Execution
You Request an HTML
Server finds and downloads the page
Browser displays the page
ASP Page Execution
ASP Compared to Other Scripting Languages
  • ASP and /JSP/PHP/Perl/CGI execution are roughly
    equivalent in execution sequence
  • Compared to client-side VBScript, ASP does not
    have to worry about browser incompatibility
  • Compared to client-side JavaScript, dont have to
    worry about browser versions or disabling

ASP in the Microsoft Language Family
  • The ASP commands...

Visual Basic
  • But theres more to ASP than just code...

ASP in the Microsoft Language Family
  • Some characterize ASP as more or less
    server-side VBScript
  • Arguments supporting this statement
  • Syntax is largely the same
  • Arguments against this statement
  • More security in connecting to Databases
  • More extensibility provided by the use of COM/DCOM

ASP in the Microsoft Language Family
  • ASP can also interact with other Microsoft
    languages or applications
  • Execute SQL commands
  • Open and close databases
  • Create and Modify database tables
  • Control applications or COM objects written or
    compiled in other languages (VB, C, Java)
  • Extract content from Excel or Word
  • Control an XML document

ASP Crash Course
  • Embedding ASP in HTML
  • Adding dynamic content
  • Variables and data types
  • Operators
  • Control Structures
  • ASP Objects
  • Forms handling and Querystrings
  • Session Handling
  • Session and application scope global.asa
  • Cookies

ASP Crash Course (cont.)
  • Embedding ASP in HTML
  • lthtmlgt
  • ltbodygt
  • ltstronggtHello World!lt/stronggtltbr /gt
  • lt
  • Response.Write ltbgtMy First ASP pagelt/bgt
  • gt
  • lt/bodygt
  • lt/htmlgt
  • Tagging
  • lt _at_LANGUAGE VBScript gt
  • ltgt
  • Script ltscript languageVBScript

ASP Crash Course (cont.)
  • Dynamically generated content
  • lt If Date() gt CDate("5/25/01") Then gt
  • ltpgtAnalytical Ultracentrifugation Workshop
    (May 21-23, 2001) and Symposium (May 24, 2001) at
    the National Analytical Ultracentrifugation
    Facility, Storrs, Conn. For additional
  • ltulgtltligtlta href"http//
    biotc/99wkshp.html" target"_blank"gtNational
    Analytical Ultracentrifugation Facilitylt/agtlt/ligt
  • ltligtlta href"naufworkshop.asp"gtAnalytical
    Ultracentrifugation Workshop and Symposium
    Description and Registration (PDF
  • lt/ulgt
  • lt End If gt

ASP Crash Course (cont.)
ASP Crash Course (cont.)
  • Including code/HTML into your page
  • lt
  • Set objRec Server.CreateObject("ADODB.Recordset
  • Set objConn Server.CreateObject("ADODB.Connecti
  • gt
  • lt!-- INCLUDE FILE "../" --gt
  • lt!-- INCLUDE FILE "../connection.asp" --gt
  • lt
  • objRec.Open "Articles", objConn, adOpenKeyset,
    adLockOptimistic, adCmdTable
  • gt
  • Include file are executed before the scripts
  • Confidential info must be stored in files with
    .asp extension
  • Content can be included from a local or remote

ASP Crash Course (cont.)
  • Variables
  • Variable names must begin with alphabetical
  • Variable names must not contain embedded full
  • Variable names are case-insensitive
  • Max length 255
  • All variables have local scope
  • Example
  • Numberoftowns 6
  • Capital Nicosia

ASP Crash Course (cont.)
  • Data Types
  • As with many scripting languages ASP (VBScript)
    does not have explicit data types
  • Only one data type called Variant
  • Can store any data type
  • ASP automatically assigns subtypes to Variants
    i.e. numeric (integer, single, double), string,
    data, boolean and special
  • Forcing a data type by casting
  • strPi 3.142
  • intPi CInt(strPi)
  • dbPi CDbl(strPi)

ASP Crash Course (cont.)
  • Operators
  • Assignment (e.g. )
  • Arithmetic (e.g. , -, ,/)
  • Comparison (e.g. lt, gt, gt, ltgt)
  • Logical (e.g. AND, OR, NOT)
  • Arrays
  • One-Dimension Dim MyArray(10)
  • Multi-Dimension Dim MyMultiArray(10,10)

ASP Object Model
  • ASP itself is not Object-Oriented. ASP can use
    objects but cannot define new objects
  • Composed of
  • 5 objects
  • 5 components

ASP Objects
  • Built-in objects that allows for the following
  • Communicate with a Web browser
  • Gather data sent by HTTP request
  • Distinguish between users
  • Objects
  • Request
  • Response
  • Server
  • Application
  • Session

ASP Objects
  • Response Object
  • Sends information to client (HTML, text)
  • lt _at_LANGUAGE VBScript gt
  • lt
  • Option Explicit
  • gt
  • ltheadgt
  • lttitlegtA Simple ASP Examplelt/titlegt
  • lt/headgt
  • ltbodygt
  • ltpgtltstronggtA Simple ASP
  • lttable border "6"gt
  • lttrgtlttdgt
  • lt Response.write ltBgt FormatDateTime( Now,
    vbLongDate ) lt/Bgtgt
  • lt/tdgtlt/trgtlt/tablegt
  • lt/bodygt
  • lt/htmlgt

ASP Objects
  • Redirect to another page
  • ltif Request.Form("selection")ltgt"" then      
    Response.Redirect(thispage.asp)end ifgt 
  • Ending the execution of a page (and script)
  • lthtmlgtltbodygt
  • ltpgtI am writing some text. This text will never
  • lt
  • Response.End
  • gt
  • finished! It's too late to write more!lt/pgt
  • lt/bodygtlt/htmlgt

ASP objects
  • Request Object
  • Handles GET or POST information
  • Data provided by the user in an HTML form or
    passed by the querystring
  • Access to information stored on client machine
  • i.e. userlogin Request.Form(login)
  • i.e. selection Request.Querystring(selection)

ASP Objects Example
  • ltheadgt
  • lttitlegtName Requestlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltp style "font-family arial,
  • Enter your name
  • lt/pgt
  • lt!-- request name.asp when posted --gt
  • ltform action "name.asp" method
  • ltinput type "text" name "namebox"
    size "20" /gt
  • ltinput type "submit" name
  • value "Enter" /gt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt

ASP Objects Example
  • lt _at_LANGUAGE VBScript gt
  • lt
  • ' Another simple ASP example
  • Option Explicit
  • gt
  • ltheadgt
  • lttitlegtName Informationlt/titlegt
  • ltstyle type "text/css"gt
  • p font-family arial,
  • font-size 14pt color
  • .special font-size 20pt color
  • lt/stylegt
  • lt/headgt
  • ltbodygt
  • lt!-- retrieve and display namebox's value
  • ltpgtHi lt Response.write Request.Form(
    "namebox" ) gt, lt/pgtltbr /gt
  • ltp class "special"gtWelcome to ASP!lt/pgt
  • lt/bodygt
  • lt/htmlgt

ASP objects
  • How the information is handled
  • Main communication device between pages and the
    server is by Forms
  • Information can be transmitted or transferred
    from page to page in an application by
  • Submitting a form
  • Sending a URL-encoded string
  • Storing data as a Session variable

ASP Objects
  • Server Object
  • Provides access to server methods or properties
  • Examples
  • Create an instance of an ActiveX Component
  • ltSet objRecServer.CreateObject("ADODB.Recordse
  • Convert a virtual path to physical path
  • Server.MapPath(login.asp)
  • Perform HTML encoding
  • Server.HTMLEncode

ASP Objects
  • Application Object
  • An ASP application is a series of pages that are
    linked together through code
  • Application_OnStart Event Runs once when the
    first page of your application is run for the
    first time by any user
  • Application_OnEnd Event Runs once when the web
    server shuts down
  • Store application level variables (kind of
  • All must be done within the global.asa file
  • One per application
  • Placed at the root directory
  • Called when an application starts/ends

ASP Objects global.asa
  • Global.asa
  • ltSCRIPT LANGUAGE'VBScript' RUNAT'Server'gt
  • Sub Application_OnStart
  • application(connectionstring) DSNconn
  • End Sub
  • Sub Session_OnStart
  • Session(lng) EN
  • End Sub
  • lt/SCRIPTgt

ASP objects
  • Session Object Session Handling
  • Web is stateless/connectionless
  • Need a way to track information per user
  • Session ID
  • randomly generated
  • stored as a cookie on the clients browser
  • security issues (session hijacking)
  • Stored on the web server
  • Session_OnStart Initiates when user establishes
  • Session_OnEnd Expires when user closes
  • Set in the Global.asa

ASP Objects
  • Use Session Object to
  • Be notified when a user session starts
  • Be notified when a user session ends
  • Store user-specific information (very important)
  • Example
  • Page 1
  • ltSESSION(FName) Request.Form(FName)
  • SESSION(lName) Request.Form(lName)
  • gt
  • Page 2
  • lt
  • Response.Write SESSION(FName) . .
  • gt

ASP Cookies
  • For persistent cookies (set before the ltHTMLgt
  • To write a cookie use
  • Response.Cookies(lang) EN
  • To retrieve a cookie use
  • Lang Request.Cookies(lang)
  • To set an expiration date
  • Response.Cookies(lang).Expires Date() 1
  • To delete a cookie
  • Response.Cookies(lang).Expires Date() - 1

ASP Components
  • Scripting Objects Component
  • File System
  • Dictionary
  • ADO (ActiveX Data Objects) Component
  • Connecting to Databases and data stores
  • Ad Rotator Component
  • Browser Capabilities Component

Connecting to databases
  • Primary reason why ASP technology was created
  • Two methods
  • Via ODBC
  • Via OLE-DB objects (faster)
  • Highly facilitated by ADO technology which stands
    above ODBC/OLE-DB
  • ASP can connect to virtually any data store

  • ODBC Open Database Connectivity is a standard
    method of connecting an application or system to
    a database. Most database vendors provide ODBC
    drivers so that you can use ODBC as a method of
    connecting to and querying their database.
  • DSN Data Source Name is a joining point between
    the database server and any application wishing
    to query the database. Programs then wishing to
    connect to and query a database using ODBC can
    reference this DSN to point to the required
  • OLE-DB Microsoft alternative to ODBC its
    faster and is based on data consumers and data
  • ADO ActiveX Data Objects is a Microsoft to hide
    all the complexities of OLE-DB and ODBC and is
    what we use to store and retrieve information
    from data stores

Connection Strings
  • DSN requires DSN
  • DSN Contacts UIDweb_user PWDnone
  • DSN-less (MS Access)
  • DriverMicrosoft Access Driver (.mdb)
  • DBQC\inetpub\wwwroot\MyWeb\Contacts.mdb
  • DSN-less (MS SQL Server)
  • DriverSQL Server ServerSQLServer
    DatabaseContacts UIDweb_user PWDnone

  • Three basic objects
  • Connection
  • Handles the retrieval and storage to the
    datastore Set objConn Server.CreateObject("ADO
  • Command
  • Handles the retrieval and storage to the
    datastore with extended functionality (stored
    procedures with data types)
  • Set objCommand Server.CreateObject("ADODB.Comm
  • Recordset
  • Contains the set of data retrieved from the
  • Set objRec Server.CreateObject("ADODB.Recordse

  • lthtmlgt
  • ltheadgtltTITLEgtLogin Pagelt/TITLEgt
  • ltmeta http-equiv"Content-Type"
    content"text/html charsetwindows-1252"gt
  • ltLINK href"style.css" relstylesheet
    titleunit_style typetext/cssgt
  • ltbase target"main"gtltBASE target_selfgtlt/headgt
  • ltBODY bgColorffffddgtltPgtltBRgtlt/pgt
  • ltUserLogin Request.Form("UserLogin")
  • UserPassword Request.Form("UserPassword")
  • ' Validate Nulls
  • If IsNull(UserLogin) OR IsEmpty(UserLogin) Then
  • Response.Write "You did not enter your Login
  • Else
  • Set objConn Server.CreateObject("ADODB.Connecti
  • Set objRec Server.CreateObject("ADODB.Recordse
  • lt!-- INCLUDE FILE "connection.asp" --gt
  • lt!-- INCLUDE FILE "" --gt
  • lt
  • SQLstr"Select from Users Where user_Username
    '" UserLogin "'"
  • objRec.Open SQLstr, objConn, adOpenKeyset,
    adLockReadOnly, adCmdText

ltobjConn.Open "DSNcms_datagt
  • Set Conn Server.CreateObject("ADODB.Connection")
  • Conn.Open DSNTOPDB"
  • SqlStr "Select from tblCompany WHERE
    CompanysName'" Session("CName") "'"
  • SET RS Server.CreateObject("ADODB.Recordset")
  • RS.ActiveConnection Conn
  • sqlStr , objConn, adOpenKeyset,
    adLockReadOnly, adCmdText
  • If Not (RS.EOF) Then
  • str "ltligtltfont color3333FFgtltbgtCompany name
    already exists! Please choose another "
  • showError str, "Add_Company.asp"
  • Response.End
  • End if
  • Set objCommand Server.CreateObject("ADODB.Command
  • strConnect DSNTOPDB"
  • objCommand.ActiveConnection strConnect

Add records to database Method using Command
  • ltSet objConn Server.CreateObject("ADODB.Connect
  • Set objRec Server.CreateObject("ADODB.Recordset"
  • lt!-- INCLUDE FILE "" --gt
  • lt!-- INCLUDE FILE "connection.asp" --gt
  • lt
  • if request.querystring("task") addnew" then
  • objRec.Open "Customers", objConn, adOpenKeyset,
    adLockOptimistic, adCmdTable
  • objRec.AddNew
  • objRec("cus_FName") Request.Form("FName")
  • objRec("cus_LName") Request.Form("LName")
  • objRec("cus_Address") Request.Form("Address")
  • objRec("cus_Town") Request.Form("Town")
  • objRec("cus_Country") Request.Form("Country")
  • objRec("cus_Email") Request.Form("Email")
  • objRec("cus_login") Request.Form("UserName")
  • objRec("cus_Password") Request.Form("Password")

Insert record into database Method using ADO
Tools You Need to Create ASP Applications
  • Web Server that Supports ASP
  • Microsoft Internet Information Server (IIS)Web
    services of Windows NT Server 4.0 and Windows
    2000 Server
  • Microsoft Personal Web Server (PWS) Creates a
    fully functional subset of IIS 4.0 that can run
    on all other Windows OS
  • PWS is an add-on for Windows NT, 95/98/Me
  • Built-in to Windows 2000/XP PROFESSIONAL
  • Fundamental knowledge of Visual Basic

Tools You Need to Create ASP Applications
  • If you are working with database
  • Knowledge of Access, SQL Server, etc. (to create
    databases and tables)
  • Knowledge of SQL commands (or at least how to use
    Access to generate SQL statements)
  • Knowledge of the VB style of data handling (ADO)
  • Authoring tool(s)

ASP Application Development Tools
  • Development Tools
  • Microsoft Visual InterDev
  • Visual Studio .NET
  • Microsoft FrontPage
  • Visual Basic
  • Microsoft Access
  • Other Non-Microsoft Tools (editors)

Steps to start developing
  • Create Web application in Internet Information
    Server (IIS)
  • Create MS Access Database
  • Create ODBC to point to MS Access
  • Open application with Microsoft FrontPage or any
    other tool to prepare layout
  • Open application with Visual InterDev or any
    other tool (FrontPage) for writing code
  • Test application using the browser

Create Web application in Internet Information
Server (IIS)
  • Create a folder with your application name in
  • Go to IIS Control Panel-gtAdministrative
    Tools-gtInternet Information Server
  • Find folder created -gtGo to Properties
  • Click on create application - Sample
  • Create a test page and test that application is
    working http//localhost/hw1/test.asp

Create MS Access Database
  • Create a new Access database
  • Save into a folder outside the Web Root (for
    security reasons not required for the
  • Give write permissions to the database file for
    the anonymous user (IUSR-ComputerName)- sample

Create ODBC to point to MS Access
  • Go to Control Panel-gtAdministrative Tools-gtData
    Sources (ODBC)
  • Create a System DSN
  • Give it a meaningful DSN name

Open application with Microsoft FrontPage
  • Start FrontPage
  • Go to File-gtOpen Web
  • Type http//localhost/hw1
  • Might be necessary to convert folder to web
  • WYSIWYG Microsoft Word style

Open application with Visual InterDev for writing
  • Visual InterDev is a part of Microsoft Visual
    Studio 6
  • Alternatively use FrontPage or Notepad

Test application using the browser
  • http//localhost/hw1

ASP Reference Tools
  • Microsoft Web Site (
  • Knowledge Base for different Microsoft products
    and Web developer issues
  • MSDN (Microsoft Developer Network) Web site for
    subscribers and/or owners of VStudio
  • Google or other search engines
  • http//
  • http//
  • http//

ASP Reference Tools
  • ASP Reference Books
  • ASP Developers Guide, by Greg BuczekISBN
  • Beginning Active Server Pages, by Francis et
    alISBN 1-861001-34-7
  • Professional Active Server Pages, by Francis et
    alISBN 1-861001-26-6

Online version of this book is on the Microsoft
Web sitehttp//
ASP Reference Tools
  • ASP Reference Books (continued)
  • Using Active Server Pages, by Scot JohnsonISBN
  • VBScript
  • VBScript Unleashed, by Petrousos, Schongar et
    alISBN 1-57521-124-6

Major Sites Using ASP
  • Beckman
  • PC-Mac
  • State Farm and Allstate Ins. Companieswww.statefa /

Myths/Criticisms of ASP
  • ASP is Microsoft/Windows centric
  • ASP doesnt work with Netscape
  • ASP pages are not recognized by Search Engines
  • ASP is slow because its interpreted (or
    because its Microsoft)
  • ASP doesnt work with client-side scripting
    languages, especially JavaScript

  • ASP is another tool in your arsenal to control
  • ASP may lead you to the dark side programming
    mainly a script language
  • Future of ASP What Lies BeneathMicrosoft
    FrameWork.NET, a successor to Visual Studio
    compiled ASP

(No Transcript)
(No Transcript)