Transcript Lecture10
COMP2121
Internet Technology
Richard Henson
April 2011
Week 10: Running Dynamic
Web pages
Objectives
– Explain briefly how the .net framework
uses programming code running on a web
server
– Explain what .net controls controls are, and
why they are so useful in server scripting
Advantages of using
ASP.NET scripts
Asp.net code:
– is compiled, not interpreted
» v1 relied on an additional /bin folder for deployed
“assemblies” or “controls” containing executable code
» v2 onwards used /app_code folder – latter more flexible;
could be referred to directly from a site configuration file
– uses xml-type tags
– can be written using a variety of programming
languages
» language declared at beginning of file
– is full object-oriented and can easily be used as
“controls” to respond to on-screen “events”
Running controls with ASP.NET
Microsoft developed an “intermediate
language” (IL) for .net framework
– could be readily converted into machine code
but the IL not easily hacked
Source code for .net development can be
written in any language that can be
translated into IL
– VB.NET built on existing practice from asp
– C# has proved to be most popular with
developers, many of whom had previously used
“C” and C++
» why use VB.net, when you can use C…?
Components of the evolving
.net framework
Evolving?
– now at version v4.0
.net common language infrastructure (CLI)
– “managed execution” framework for scripts on an
IIS web server
– runs Intel x86 IL (Intermediate Language) code
» Common Language run-time (CLR) for executing
controls
» ready to run
» development language irrelevant
Components of the evolving
.net framework
/App_Data folder for database, web
applications also must have a web.config file
in the application root folder
As well as app_data folder, .net apps from v2
onwards also support the following additional folders:
– app_code for “assemblies” (compiled code) &
executables
– app_browsers, app_themes, app_localresources,
app_globalresources, app_webreferences…
How the .net environment
manages an application
“Assemblies” from .aspx files added to
/app_code folder
CLI executes IL assemblies as CLR (runtime)
– just a set of Win32 DLLs (dynamic link library files)
created by compiling the assembly components
» written in IL
» makes sure script execution is “controlled” and kept
within memory boundaries
– loaded implicitly when a .net application is run
Mechanism of Loading
Assemblies for processing
“AppDomain” sets up a security boundary in
memory for each application
Code (.exe, or .dll) loaded into process
“spaceperfo”
JIT (Just in Time) compilation ensures “flat
out performance” of the application…
– cf Wallace & Grommit – latter lays out the track as
the train is about to pass along it
HTTP processing
Whole .net architecture designed “with failure in
mind”
– overall control with http.sys process
– if memory usage gets too large…
» whole .net framework pulled down and restarted…
Each AppDomain uses a pipeline of objects to
handle requests
–
–
–
–
Httpapplication – oversees flow
Httpcontext – tracks “per request” state
Modules – generic “pluggable services
Handlers – http requests
Covers most (all?) eventualities and makes sure
requests are correctly dealt with – no muddling of
threads (!)
Very Useful ASP.net components:
1. Web Controls
Reusable classes used to render parts
of a page
– Similar to Windows “forms”
New control created for each request
» view state/Event tracking handled automatically
A typical web page may have a
hierarchical structure of web controls to
makes them easily manageable
Very Useful ASP.net components:
2. Event Handlers
HTTP is stateless (no data retention)
– no multi-step processes possible
– e.g. HTML form contents disappear once form
submitted
Web Controls provide scope for handling
events, when triggered (or raised)
– e.g. Page_Load, OnClick
– “PostBack architecture”
– allows web forms data to reappear on the screen
Very Useful ASP.net components:
3. Master Pages & Themes
Master Page
– resides in .master file
– defines template for other pages
» cf PowerPoint slide master
– Contains top <html>, <body>, <form> tags
– “Page” command utilises master either “static” or “dynamic”
– “Page_init” process renders components
Themes
– allow common styles to be applied across a series of pages
Developers can still use .CSS files
– fully supported by the master file and page “themes”
concepts
.net Development and RAD tools
Don’t be phased by the .net architecture and
use of a programming language like C…
– the syntax of object-oriented C# is similar to Java
– RAD tools such as Dreamweaver (earlier
versions) and Visual Web Developer make
development easy by…
» providing a range of web controls already written in C#
and ready to compile
» helping with putting controls/assemblies into the
/app_code folder
» setting up the web.config file
– many other previously written controls are
available on the web
Using Relational Databases
Real advantage of a true relational
database is that SQL can be used for r/w
& query database operations
– so .net work with database involves AQL
queries as well
– As before, the RAD environment can use
wizards to write the queries for you…
Databases and the .net
architecture
To make a two-way link between database
and server scripts, it is just necessary to:
– make relevant Microsoft data access components
(MDAC) available …
– define “datasets” (aspx) for the database using a
programming language & embedded SQL
– provide connectivity link to the database using the
appropriate web control
Microsoft Data Access
Components (MDAC)
Provide connectivity between the system
and a wide range of databases
Easily downloaded:
» www.microsoft.com/data/download_21242023.htm
Just because a database type doesn’t
seem to be represented, doesn’t mean that
it can’t be… MDAC is regularly updated
Database Design
Same principles apply as with any other relational
database management system (RDBMS)…
– identify entities & attributes
– produce entity relationship
» define logic relationships between entities
– make sure data is fully normalised
» create tables & links
– use embedded SQL statements in the server script to
communicate with the data:
» extract data from specific fields in particular tables
» put data into specific fields in particular tables
However, some “self-taught” developers will be
unaware of this, and try to build the data round the
processing…
Evolution of connectivity
between Applications & RDBMS
In the early web development days…
– for the connection of an application to a relational
databases…
– a client application had to be written to use the
proprietary API (application program interface)
Even then, there was a problem:
– what if more than one RDBMS needs to be used?
The solution would be to use several different
APIs (Application Programming Interfaces)
– each needed a client application…
– added greatly to the complexity of the task!
The Microsoft Solution:
the ODBC API
Aspiration: the “Universal Data Access” (UDA) model
– all data consumers interact with all data providers…
– response to the “API for each application” problem
First stage: ODBC = Open Database Connectivity
Developed in early 1990s:
– common API for writing applications to access ANY relational
DBMS for which an ODBC driver had been written
Once the APIs had all been written, tried, and
tested…
– any relational database with an ODBC compliant interface
could use them
– DSN model offered easy database path connectivity string
management
ActiveX
The next stage in evolution of Microsoft’s
data objects model
– sexy name for OLE v2.0
– made up of…
» OLE
Object Linking and Embedding…
» Combined with COM
Common Object Model
ActiveX Data Objects make up a series of
modular components called ADO
– used for “run-time” web applications
– basis of .net controls
More about ActiveX
Data Objects (ADO)
Designed to simplify the writing of client
applications to access data sources
through OLE DB providers
– more flexible than the earlier ODBC model
» had to be specified on the local machine
» limited to the data providers on that machine
Active X uses a common, easy-to-use
object model
– data sources can now also include:
» spreadsheets
» graphics
» web pages
OLE DB
Application of OLE/ActiveX principles to
connectivity between applications and
relational database management
systems
– interface specification provides a layer of
abstraction between:
» a data provider e.g. relational DBMS
» a data consumer e.g. business object or client
application
Universal Data Access in practice
Making a connection to a
database on the web server
Each new version of .net provides more
database controls
RAD tools very helpful at making these
accessible…
– server-script can then use SQL commands
to link to and communicate smoothly with
database tables
– can save a lot of time…
How FTP works
Used with TCP/IP to send files from one site
(server) to another (client):
– all Internet Servers have unique IP addresses
– IP address used by IP protocol to manager
transfer of data packets from one site to another
– TCP used to arrange packets into the correct
order, through listening on port 21 (as opposed to
HTTP packets, which use port 80)
– data rearranged into correct format for screen
presentation by FTP protocol
How FTP works
Server offers FTP as a web service
– username/password controlled access to
folders
– tends to be associated with a www service
Device defined to be accessed through
TCP port 21
FTP service accessed by FTP clients
via TCP/IP and the Internet
FTP Servers
Set up (by default) to listen for FTP requests
on TCP port 21
During FTP access:
– FTP client tools attempt to log on to the server,
and get access to the directory or directories
provided by the service
– FTP client tool receives/sends selected files
from/to appropriate directory on the FTP server
– communication channel is terminated
Windows FTP Servers
FTP service provided as a component
of:
– Internet Information Server (Microsoft)
– Apache web server
Other third party products:
– WS FTP server (Ipswitch)
– FTP Serv-U
Unix FTP servers
NOTE: to avoid upsetting Unix’s file
system, filenames should be lower case
and avoid punctuation
Examples:
– ftpd (ftp daemon) – based on original
DARPANet specification
– Apache web server (originally for Unix)
Thanks for listening…