Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)

Similar presentations


Presentation on theme: "Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)"— Presentation transcript:

1 Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)

2 Mark Dixon Page 2 C3 (in-class test) Results Student Number Score (max 50) Classification is for guidance only Please feel free to come and discuss your results with me

3 Mark Dixon Page 3 Session Aims & Objectives Aims –To introduce the fundamental ideas involved in server-side code Objectives, by end of this week’s sessions, you should be able to: –add dynamic server-side functionality, using VB Script

4 Mark Dixon Page 4 Example: Logon page Logon pages – probably most common page –hotmail –Amazon –University portal –utility bills (gas, electricity, phone, internet) –Travel (flights, ferry, car rental)

5 Mark Dixon Page 5 Example: Logon Restrict access to home page

6 Mark Dixon Page 6 Example: Logon - code (v1) Using Client-side VB Script: Sub btnLogon_OnClick() If txtUserName.value = "mark" And txtPassWord.value = "soft131" Then window.navigate "Home.htm" Else window.navigate "LoginFail.htm" End If End Sub Please logon: Logon.htm My Home page Welcome to my home page. Home.htm Sorry, those login details were incorrect. Please try again LoginFail.htm

7 Mark Dixon Page 7 Problem: View Source View Source – shows client-side script: Reveals both username & password

8 Mark Dixon Page 8 network connection Web Hardware and Software Client Server Browser Application (MS Explorer, Netscape) Web-server Application (MS IIS, Apache)

9 Mark Dixon Page 9 Request-Response Cycle: HTML Browser Application (MS Explorer, Netscape) Web-server Application (MS IIS, Apache) http://mdixon.soc.plym.ac.uk/ Request Mark Dixon's web site Mark Dixon's web site Welcome to my web server. Please select from the following list: Soft131: Introduction to programming for Multimedia and Internet applications. Response

10 Mark Dixon Page 10 Request-Response Cycle: CSC Browser Application (MS Explorer, Netscape) Web-server Application (MS IIS, Apache) Logon.htm Request Sub btnLogon_OnClick() If txtUserName.value = "mark" And txtPassWord.value = "soft131" Then window.navigate "Home.htm" Else window.navigate "LoginFail.htm" End If End Sub Please logon: Response Client-side code: Code sent to Client Interpreted by browser

11 Mark Dixon Page 11 Request-Response Cycle: SSC Browser Application (MS Explorer, Netscape) Web-server Application (MS IIS, Apache) http://localhost/datetime.asp Request Today's date The date today is 21/11/2005 The time is currently 10:28:18 Response Today's date The date today is <% Response.Write(Format(Now, "D")) %> The time is currently <% Response.Write(Format(Now, "T")) %> Server-side code: Interpreted by server (code never sent to Client)

12 Mark Dixon Page 12 Server-side Script (what) ASP – active server pages –executed on server takes time – request-response cycle requires server software (e.g. IIS) –code not sent to client code secure (can't be viewed by client) –results (response) sent to client pages will NOT work by double clicking on file

13 Mark Dixon Page 13 Server-side Script (how) ASP code: –.aspx (not.htm) –between –Response object: page sent back to client write method: adds text to response object –Now object: current date (server) Today's date The date today is <% Response.Write(Format(Now, "D")) %> The time is currently <% Response.Write(Format(Now, "T")) %> Date.aspx

14 Mark Dixon Page 14 Form Submission action attribute submit button Login Please login: Username: Password: Login.htm

15 Mark Dixon Page 15 Form Processing Login <% If Request.Form("txtUserName") = "George" Then Response.Write "Login successful." Else Response.Write( "Invalid user name.") End If %> LoginCheck.aspx

16 Mark Dixon Page 16 View Source Code executed at server –code is never sent to client View, Source – does not show code:

17 Mark Dixon Page 17 Code Execution Login <% If Request.Form("txtUserName") = "George" Then Response.Write("Login successful.") Else Response.Write("Invalid user name.") End If %> LoginCheck.aspx Server SW (IIS) Login Invalid user name. Response

18 Mark Dixon Page 18 Example: Logon - code (v2) Using Server-side VB Script: Please logon: Logon.htm <% If Request.Form("txtUserName") = "mark" And Request.Form("txtPassWord") = "soft131" Then Response.Redirect("home.htm") End If %> Sorry, those login details were incorrect. Please try again LoginFail.aspx My Home page Welcome to my home page. Home.htm

19 Mark Dixon Page 19 Running your ASP page within Visual Studio –Run (play) button (F5) –only available to you on development PC using Internet Information Services (IIS) –makes PC a server –page available to all computers on internet

20 Mark Dixon Page 20 IIS - Installing IIS / personal web server on Windows CD Start, Settings, Control Panel, Add/Remove Programs Add/Remove Windows Components IIS

21 Mark Dixon Page 21 IIS: Enabling/Disabling Start, Settings, Control Panel, Administrative Tools, Internet Services Manager Stop Start

22 Mark Dixon Page 22 IIS: Exposing pages Put ASP pages in: –C:\INetPub\wwwRoot (this part of hard disk exposed to outside world) Execute pages by putting: –localhost (in web browser, e.g. IE, means local machine) ASP pages don't work by double-clicking

23 Mark Dixon Page 23 IIS – Date.asp localhost/test/date.aspx C:\INetPub\wwwRoot\Date.aspx

24 Mark Dixon Page 24 Reference: Server Object Model Request object: calling web page –Form: used to get form data from previous page Response object: web page sent back –Write: used to put text into web page –Redirect: used to navigate to other page –Clear: erases all HTML in web page

25 Mark Dixon Page 25 Client-side vs. Server-side Code Sub btnLogon_OnClick() If txtUserName.value = "mark" And txtPassWord.value = "soft131" Then window.navigate "Home.htm" Else window.navigate "LoginFail.htm" End If End Sub Please logon: Logon.htm <% If Request.Form("txtUserName") = "mark" And Request.Form("txtPassWord") = "soft131" Then Response.Redirect("home.htm") End If %> Sorry, those login details were incorrect. Please try again LoginFail.aspx Both use VB Script language (i.e. Sub, If, Dim, For, etc.) Objects are different

26 Mark Dixon Page 26 Tutorial Exercise: Login Task 1: Get the Login (v2) example from the lecture working. Task 2: Copy your web site to C:\INetPub\wwwroot and access it via localhost Task 3: Try accessing other peoples pages Note: the domain names of the lab PCs are their serial numbers (written on the side of the base unit - TO???????)

27 Mark Dixon Page 27 Tutorial Exercise: Multiply Task 1: Create a new web site, that multiplies two numbers entered into text boxes by the user.


Download ppt "Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)"

Similar presentations


Ads by Google