the problem of state. we will look at… sometimes web development is just plain weird! internet /...
TRANSCRIPT
![Page 1: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/1.jpg)
The Problem of State
![Page 2: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/2.jpg)
We will look at…Sometimes web development is just plain
weird!
Internet / World Wide WebAspects of their operationThe role of clients and servers
ASPX Page (Web Form)How it is passed between browser and serverThe structure of the pageHow it provides functionality to the browser
The problem of state
![Page 3: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/3.jpg)
The Internet and TCP/IP
Network of networks Defence research in the 60sTCP/IP (Transmission Control Protocol /
Internet Protocol)Allows programs on computers to talk to
each other
![Page 4: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/4.jpg)
The IP AddressUniquely identifies each machine32 bit number made up of four 8 bit numbers Visit http://209.85.227.105/
Assigned in blocks
www.dmu.ac.uk 146.227.160.79www.cse.dmu.ac.uk 146.227.57.2G677 (my server) 146.227.53.94
![Page 5: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/5.jpg)
Name Servershttp://209.85.227.105/ not obviously www.google.com
![Page 6: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/6.jpg)
PortsTCP/IP allows programs on machines to
communicateIP address identifies machineport number identifies programThere is no law that states a specific port must be
used for a service however there are certain ports that traditionally provide services.
80 HTTP (web pages)21 FTP (File transfers)119 NNTP (Network News Transfer Protocol)443 HTTPS (secure web pages)
![Page 7: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/7.jpg)
The Good Old DaysUp until about 1989 the Internet existed
quite happily without the World Wide Web
File Transfer Protocol (FTP) TelnetUsenet
World Wide Web - Is not the internet!
![Page 8: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/8.jpg)
The Web’s Client Server Model
![Page 9: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/9.jpg)
Where is Client and Server in Visual Studio?
![Page 10: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/10.jpg)
Server v Client Side CodeCode may be added at either end of the process
Client side code runs at browserAction Script (Flash)JavaScript VBScript
Server Side CodeASP.NET (C # VB.NET)PHPJSP
![Page 11: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/11.jpg)
Server Side Code – Dynamic Pages
![Page 12: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/12.jpg)
HTML Forms GET and POSTHTML allows simple form creation
![Page 13: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/13.jpg)
HTML Form Code
Change POST to GET
http://g519-md.ad.cse.dmu.ac.uk/Request/?txtFirstName=Matthew&txtLastName=Dean&Submit1=submit
![Page 14: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/14.jpg)
Active Server Pages (ASPX)Events & Handlers User triggered events
Click Triggered when a user presses a button
Selected Index Changed Activated when the user selects an item off a drop down list
System generated
Load Runs when the ASPX page is loaded by the server
Unload Runs when the ASPX page is unloaded from the server
![Page 15: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/15.jpg)
Create a Similar Form in ASP
![Page 16: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/16.jpg)
Active Server Controls
Note the tag <asp
![Page 17: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/17.jpg)
Post Back = FalsePost back is false on the first HTTP request
The browser sends the request to the server for the page
The server runs the page load eventThe server runs page unload eventASPX controls converted to HTML and sent to
the requesting browser
![Page 18: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/18.jpg)
What the Browser Gets…ASP & Code never makes it to the browser!
![Page 19: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/19.jpg)
Post Back = True
The browser sends the HTTP request to the server
The server runs the page load eventThe server runs other events (in this case the
click event of the Go button)The server runs the page unload eventAll asp controls changed into suitable HTML
controls and sent back to the requesting browser
NOTE Load and Unload Events ALWAYS RUN!
![Page 20: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/20.jpg)
The Problem of State We have seen the following points
The web follows a client server mode of operation The ASPX page is rendered on the server and sent to the browser as HTML The page is rendered in two modes
PostBack = False
(The first time the page is requested, Load – Unload events) PostBack = True
(Subsequent renderings of the page, Load – Other Events – Unload)
The thing to note in all of this messing about is that the settings of
the page are not automatically remembered on each round trip. The web is referred to as stateless.
So how is this problem addressed?
![Page 21: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/21.jpg)
Use CookiesCookies are small files stored on the client
computer that allow the web page to record details of its visit to that machine.
Cookies may be turned off by the user of the
client machine.
Not suitable for sensitive data.
![Page 22: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/22.jpg)
Use a Query String
This is achieved by setting the HTML forms method to Get rather than Post.
This is a good technique so long as the data isn’t a
potential security risk. This would be a very bad query string. http://www.mysite.com/login.asp?
UserName=Fred&Password=password123
![Page 23: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/23.jpg)
Use Session Variables
Use in conjunction with IsPostBack in the Load Event of the page…
Browser Server
HTTP Request
HTML Page
Load session variables in the load event
Save session variables in the unload event
![Page 24: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/24.jpg)
Potential Problem…Remember the load event runs every time the page is
processed and it is the first thing the server does. If we load the messages on subsequent renderings of the
page we get the following problem…
I click an entry in the list and press delete The load event runs re-setting the list removing my selection The delete click event fails because the list has been re-set
To avoid this kind of problem we need to check IsPostBack
to see if it is appropriate to read data at the server.
![Page 25: The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of](https://reader038.vdocument.in/reader038/viewer/2022110321/56649f535503460f94c78119/html5/thumbnails/25.jpg)
SummaryBecause the web is stateless and processes
pages the way that it does you will at some point get very confused about state!
Remember Load event runs firstOther Events nextUnload event last
Load and Unload always run!