Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.

Slides:



Advertisements
Similar presentations
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
Advertisements

Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Caching MacDonald Ch. 26 MIS 424 MIS 424 Professor Sandvig Professor Sandvig.
6/10/2015Cookies1 What are Cookies? 6/10/2015Cookies2 How did they do that?
Chapter 10 Managing State Information Using Sessions.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Chapter 10 Managing State Information PHP Programming with MySQL.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 10 Maintaining State Information Using Cookies.
Objectives Learn about state information
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Web Form Fundamentals MacDonald Ch. 5 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
Post-Module PHP Forms BTM 395: Internet Programming.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
JavaScript, Fourth Edition
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
Session and cookie management in.Net Justin Brunelle CS795 6/18/2009.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
State Management. What is State management Why State management ViewState QueryString Cookies.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
ASP.NET State Management. Slide 2 Lecture Overview Client state management options Cookies Server state management options Application state Session state.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
DAT602 Database Application Development Lecture 16 Java Server Pages Part 2.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
PHP Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
CIS 451: Cookies Dr. Ralph D. Westfall February, 2009.
Copyright ©2005  Department of Computer & Information Science Working with Cookies.
Copyright © 2006, Infinite Campus, Inc. All rights reserved. User Security Administration.
Cookies (continue). Extracting Data From Cookies Data retrieved from a cookie is a simple text string. While there is no specific JavaScript function.
©SoftMooreSlide 1 Session Tracking with Servlets.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
MIT AITI 2004 JSP – Lecture 4 Sessions and Cookies.
Maintaining State in ASP. Problem - How do I maintain state information about the user  Several Methods –Cookies –Session variables –Hidden fields 
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
Active Server Pages Session - 3. Response Request ApplicationObjectContext Server Session Error ASP Objects.
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
MIS Professor Sandvig MIS 324 Professor Sandvig
Cookies Cookie :- A cookie is often used to identify a user. A cookie is often used to identify a user. A cookie is a small file that the server embeds.
MIS Professor Sandvig MIS 424 Professor Sandvig
HTML5 and Local Storage.
ASP.NET 4.0 State Management Improvements – Deep Dive
CSc 337 Lecture 27: Cookies.
Pre-assessment Questions
Cookies A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer.
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig

Maintaining State  Tools: 1. Cookies 2. Viewstate 3. Session 4. Cache

1. Cookies  Small text files stored on user’s computer  Useful for storing: Date of last visit Date of last visit Unique user identifier Unique user identifier Preferences Preferences etc. etc.  Limitations Not secure – user can view, modify, delete Not secure – user can view, modify, delete User can disable User can disable

1. Cookies  Write: Single value per cookie: Single value per cookie: Response.Cookies[“Name”].Value = “Bart”;Response.Cookies[“Name”].Value = “Bart”; Multiple values per cookie Multiple values per cookie Response.Cookies[“Name”][“First”] = “Bart”;Response.Cookies[“Name”][“First”] = “Bart”; Response.Cookies[“Name”][“Last”] = “Simpson”;Response.Cookies[“Name”][“Last”] = “Simpson”;  Read Request.Cookies[“Name”].Value; Request.Cookies[“Name”].Value; Request.Cookies[“Name”][“First”].Value; Request.Cookies[“Name”][“First”].Value;

1. Cookies  Expiration: Default: when browser is closed Default: when browser is closed Response.Cookies[“CookieName”].Expires = DateTime.Now.AddDays(180); Response.Cookies[“CookieName”].Expires = DateTime.Now.AddDays(180); Delete Cookie: set expiration to past (-1) Delete Cookie: set expiration to past (-1)

1. Cookies  Testing for cookie Attempt to read a cookie that is not present: Attempt to read a cookie that is not present: Error: Object reference not set to an instance of an object  Solution: If (Request.Cookies[“Name”] != null) { //safe to read cookie name = Request.Cookies[“Name”].Value; } name = Request.Cookies[“Name”].Value; }

1. Cookies  Benefits: Persist between sessions Persist between sessions Keep track of usernames, last visit, etc. Keep track of usernames, last visit, etc. Easy to use Easy to use  Drawbacks: Client can block Client can block Not secure Not secure

2. Viewstate  Data in web controls automatically stored Encoded in hidden form field Encoded in hidden form field  May add to viewstate programmatically ViewState[“UserID”] = “333”; ViewState[“UserID”] = “333”;  Retrieve with same syntax Returned datatype is object Returned datatype is object Must convertMust convert int intUserID = Convert.ToInt32(ViewState["UserID"]); int intUserID = Convert.ToInt32(ViewState["UserID"]);

ViewState  Benefits: Very convenient Very convenient Can access data even when controls hidden Can access data even when controls hidden  Drawback Difficult to transfer between pages Difficult to transfer between pages Does not persist between sessions Does not persist between sessions

3. Sessions  Data stored on server  Unique to each user  Uses cookie to associate with user User must have cookies enabled User must have cookies enabled  Create: Session[“LastName”] = “Simpson”; Session[“LastName”] = “Simpson”;  Delete Session.Abandon; – Deletes the session Session.Abandon; – Deletes the session Session.Remove[“LastName”]; – removes items Session.Remove[“LastName”]; – removes items

Sessions  Expiration Default: 20 minutes Default: 20 minutes Session.Timeout = 60; Session.Timeout = 60;  Benefits Secure Secure Client cannot view, edit, deleteClient cannot view, edit, delete Automatic timeout Automatic timeout  Drawbacks Do not persist Do not persist Require cookies Require cookies Use server resources Use server resources

4. Cache  Stored on server Application Application  Often used to cache data Example: XML Music Example: XML MusicXML MusicXML Music  Store any type of data / object Stored as type “object” Stored as type “object” Recast when retrieved Recast when retrieved

Cache  Add item to cache: Cache.Insert(“key”, object, dependency, absoluteExpiration, slidingExpiration) Cache.Insert(“key”, object, dependency, absoluteExpiration, slidingExpiration)  Example: Cache.Insert(“cat30”, “apples”, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration) Cache.Insert(“cat30”, “apples”, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration)

Cache  Retrieve: If (Cache[“cat30”] != null) { string fruit = (string) Cache[“cat30”]; string fruit = (string) Cache[“cat30”];}

Cache  Benefits: Secure Secure Many expiration options Many expiration options Store any object Store any object  Drawbacks: ?? ??

When to use each: CookiesNeed data to persist across sessions Security not important ViewstateData associated with page Similar to hidden form field SessionSecure Associated with each user session CacheSecure Share data across sessions Control expiration Example: output (source)output source

Summary  Maintaining state: Method depends on needs Method depends on needs Several flexible alternatives Several flexible alternatives