COMP 3241 EBusiness Technologies Richard Henson University of
COMP 3241 E-Business Technologies Richard Henson University of Worcester October 2012
Week 2 – Early Web Applications, Active. X controls, and. net n Objectives: ØCompare and contrast embedded code for client-only applications & server scripting ØExplain how client-side VBScript evolved into run-time Active. X, which itself evolved into secure server-script ØUse a client-server. net development environment for development and testing of. net master pages and code behind
Interpreted and Compiled Languages n n Programming (source) code must be converted into “machine code” before it can be understood and acted on by the CPU This can be done in two ways: Ø convert whole program (using a compiler) and save it in a file Ø leave program as it is, and convert it (using an interpreter) one line at a time when it is needed n Compiled code generally occupies much more space than source code Ø so of more limited use on the Internet (esp. early days). . .
How do Browsers cope with source code? n Designed to use interpretation on HTML code Ø reads one line of HTML key words and their parameters and uses HTML interpreter to convert (or interpret) that line into CPU instructions Ø reads & interprets next line… and so on… Ø CPU does further processing and sends commands to the video card which creates the visual display
Embedded programming code in HTML Files n Still. html and executed on the Browser ØBrowser needs to have interpreter for that programming language e. g. » VB Script » Java Script n For the Browser to call the right interpreter, an appropriate declaration statement needs to be included in the <HTML> start line
Request and responses Organisation of application processing across a client-server network… n Client: n Ørequests services or information from another computer (e. g. the server) n Server: Øresponds to the client's request by sending the results of the request back to the client computer
Request and responses client requests information server processes the request, sends a response back to the client
Internet Communications n Based on principles of client/server networking ØEITHER Internet computer can “play” the role of client or the role of server Øe. g. (1) A user in one university sends an email to a user in another university: » “A” client sends email to “B” server Ø(2) When a reply comes back… » “B” client sends email to “A” server
Client-Server web applications & Server Scripts § Client-server web applications usually require: 1. a web server, for interpreting or compiling then processing the scripts 2. a server-end database to provide and store data 3. physical & logical connections between serverscripts, client-end input forms and server-end database 4. clearly defined locations for gathering input data at client-end, for server scripts, and for database(s)
Writing Server Scripts n n NOT saved as. html! Server code can be embedded directly into HTML code… Ø Command is needed to inform the web server » (1) that non-HTML code is about to be used » (2) when next code reverts to HTML n With. asp scripts… (no longer used) Ø the command to start the script was <% Ø to end the script… %> n With. php scripts… Ø <? php starts the script Ø ? > ends the script
Server Scripts and “Localhost” n No matter which scripting type is used, the code can be tested locally on a computer running a web server that can understand that type of script Ø how? use “localhost” in the URL at the Browser end (localhost = path to the server scripting root folder) n A typical URL for testing such a script locally could then be (depending on script type): Ø http: //localhost/scriptname. aspx Ø http: //localhost/scriptname. php
Web Dynamic Client-Server Model (1) Server-Side Processing in a typical web-based client-server application: 1. HTML form on web browser collects data at the client end 2. HTTP enables the form data to be sent to a web server
Web Dynamic Client-Server Model (2) Ø 3. web server processes the form data according to instructions on a server script called at the client end Ø 4. output from processing stored temporarily on web server
Web Dynamic Client-Server model (3) Ø 5. server script sends output back to browser with HTML code to create a structure to display the data (e. g. HTML table) Ø 6. This gets even more complex when a database, and database programming, are also involved at the server end…
Introduction to Server-scripting n The following apply to ALL types of scripting… Øreal programming code is essential » note: HTML is a FORMATTING language, NOT a programming language Øboth client and server ends need to have links to programming code: » client end…embedded within a HTML page » server end… could be embedded or separate
Languages used for Server Scripting n Much has been tried since HTML became interactive in the early 1990 s: Ø Can use an existing language in a completely separate file, which is already compiled and ready to go: » the original approach: . cgi » any language could in theory be used » in practice “C” was usually favoured Ø Can use an existing language embedded in a HTML file » The Microsoft. asp approach, using embedded VB source code » The Sun. jsp approach, using embedded Java (Script) source Ø Can utilise/invent a scripting language that is “HTML-like” and easily embeds with HTML » » » PERL Cold Fusion. cf Preprocessor Hypertext processing. php
Microsoft’s first attempt at server scripting… n In 1996, Microsoft introduced active server pages (asp) Ø hugely successful Ø soon became more popular than. cgi n However, in spite of the great success of asp, big problems were emerging… Ø by 2000, hackers were attacking Microsoft servers and finding many security holes in IIS » Microsoft only coped by offering hotfixes Ø further problem: used VB source code » if server not secure, code could be copied or compromised » Scripts could not be truly “object oriented”
ASP becomes ASP. NET n Microsoft’s new approach to server scripting for the new millennium… Ø building on asp principles Ø new system that used “intermediate language”, rather than source code on the server Ø much more difficult to hack n Security problems with VB… Ø out with the old (asp) Ø in with the new (asp. net) n New environment known as the. net framework Ø many developers accustomed to VB/. asp Ø took awhile to catch on!
Development of. NET framework for Server Scripting n BASIC and VB very much a part of Microsoft’s strategy, until circa 1999/2000… Ø use of raw source code became a security issue Ø Gates realised that e-business and e-commerce would never be reliable without using secure (and therefore compiled) code Ø Microsoft rejected their previous strategy which used source VB code and an interpreter program within IIS n What to replace VB source code with? Ø applied source VB -> Active. X run-time principles server-side Ø Server equivalent of Active. X controls could now be used/developed n Result: . net Framework & ASP. NET: Ø VB evolved into the more object oriented (and complied) VB. NET Ø. net framework provided the basis for » . net server-side controls » the ubiquitous use of compiled languages
Advantages of ASP. NET scripts compared to ASP n Compiled, not interpreted n Web Controls use xml-type tags n Can be written using a variety of programming languages Ø language declared at beginning of file Ø fully object-oriented and many controls written to respond to on-screen “events”
Which Source Code Language? n Source code for. net development can be written in any language that can be translated into IL Ø VB. NET builds on existing practice from asp Ø But… 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 a more powerful, compiled, and object-oriented language like C?
Components of the evolving. net framework n Common Language Infrastructure (CLI) at the server end (i. e. IIS) Ø “managed execution” framework for scripts Ø runs Intel x 86 IL code » common Language run-time (CLR) for executing controls » ready to run; development language irrelevant Ø /app_code folder for deployed “assemblies” or “controls” containing executable code, and databases Ø web. config file » store of configuration info e. g. a path to database file Ø from v 2 onwards the following additional folders: » app_browsers, app_themes, app_localresources, app_globalresources, app_webreferences
How the. net environment manages an application n n “Assemblies” from. aspx files added to /App_Code (usually. dll files created by compiling the assembly components) CLI executes IL assemblies as CLR (runtime) Ø makes sure script execution is “controlled” and kept within boundaries » an earlier version of IIS used to “leak” memory until the system needed rebooting Ø usually loaded implicitly when a. net application is run
Mechanism of Loading Assemblies for processing “App. Domain” sets up a security boundary in memory for each application n Code (. exe, or. dll) loaded into process “spaceperfo” n JIT compilation ensures “flat out performance” n Øcf Wallace & Grommit – latter lays out the track as the train is about to pass along it
HTTP processing n . net architecture designed “with failure in mind” Ø overall control with http. sys Ø if memory usage gets too large, . net pulled down and restarted… n Each App. Domain uses a pipeline of objects to handle requests Ø Httpapplication – oversees flow Ø Httpcontext – tracks “per request” state Ø Modules – generic “pluggable services Ø Handlers – http requests n Covers most (all? ) eventualities and makes sure requests are correctly dealt with – no muddling of threads (!)
Very Useful ASP. net components: 1. Web Controls n Reusable classes used to render parts of a page ØSimilar to Windows “forms” n New control created for each request » view state/Event tracking handled automatically n 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 n HTTP is stateless (no data retention) Ø no multi-step processes possible Ø e. g. HTML form contents disappear once form submitted n Web Controls provide scope for handling events, when triggered (or raised) Ø e. g. Page_Load, On. Click Ø “Post. Back architecture” » allows web forms data to reappear on the screen
Very Useful ASP. net components: 3. Master Pages n Master Page Ø Created as a. master file Ø defines template for other pages » cf Power. Point slide master Ø Contains top <html>, <body>, <form> tags Ø “Page” command (top of page) utilises master: » either “static” or “dynamic” Ø “Page_init” process renders components
Very Useful ASP. net components: 4. Themes n n 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 n By now, you may be thinking… Ø “Help! I can’t program in “C”!” n DON’T BE SCARED! Ø the syntax of object-oriented C# is similar to Java Ø RAD tools such as Dreamweaver (earlier versions) and Visual Web Developer (VWD) provide a range of web controls already written in C# Ø Extension Managers enable other controls to be added to the RAD environment n VWD also help with general file/folder management such as putting controls/assemblies into the right folder Ø i. e. /app_code
Managing C# Code, HTML code, and web controls n Each has its own syntax! Øearlier versions of. net had all three types together! ØMore recently “code behind” files encouraged » Standard HTML & web control file saved as. aspx » associated C# code saved as a. cs file n declared through “Page” command
Running. aspx, . cs, etc. pages toghether n All managed within the. net run-time environment Ønormally at server-end using IIS ØVisual Studio allows use of a cut-down version of IIS at client end for testing Ødeveloper doesn’t need to do anything more, provided that files all in the right folders…
Running controls & C# with ASP. NET n Semi-compiled into “intermediate language” (MSIL) for. net framework and saved together as an “assembly” Ø intermediate code executes very quickly when required…
Now you try it…
- Slides: 34