Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.

Slides:



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

Maintaining State Between the Client and Server Internet Programming Using VBScript and JavaScript 9.
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.
CIS 451: ASP Sessions and Applications Dr. Ralph D. Westfall January, 2009.
Servlets and a little bit of Web Services Russell Beale.
Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
Chapter 10 Managing State Information PHP Programming with MySQL.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
IT533 Lectures Configuring, Deploying, Tracing and Error Handling.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Session 11: Security with ASP.NET
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.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
Cookies and Security Saving the “state”
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.
First Name Last Name Please enter your logon information: John Submit Chen Web Server Login.php Web Server Hello John Chen Greetings. php Please enter.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Managing State.
State Management. What is State management Why State management ViewState QueryString Cookies.
Chapter 8 Cookies And Security JavaScript, Third Edition.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
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.
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.
© Minder Chen, ASP.NET - 1 Form Handling and State Maintenance Major Build-in ASP.NET Objects Simple Form Handling HTML Forms More Complex Form.
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.
Global.asax file. Agenda What is Global.asax file How to add the Global.asax file What are the default events available Explanation to Application_Level.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Module 7: Creating a Microsoft ASP.NET Web Application.
PHP Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
Module 1: Working with ASP.NET. Overview Introducing ASP.NET Creating Web Forms Adding ASP.NET Code to a Page Handling Page Events Discussion: ASP vs.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
Lecture Note 8: ASP Including Files and The Global.asa file.
Cookies COEN 351 E-commerce Security. Client / Session Identification HTTP Headers Client IP Address HTTP User Login FAT URLs Cookies.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Working With ASP.NET Application. Create a new virtual directory The procedure to create a new virtual directory Internet Services Manager Right click.
ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
Maintaining State in ASP. Problem - How do I maintain state information about the user  Several Methods –Cookies –Session variables –Hidden fields 
Active Server Pages Session - 3. Response Request ApplicationObjectContext Server Session Error ASP Objects.
ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC.
Personalizing Web Sites Nasrullah. Understanding Profile The ASP.NET application service that enables you to store and retrieve information about users.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
PHP – Hypertext Preprocessor.
Session Variables and Post Back
State Management.
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Internet Programming Chapter 9: State Management in ASP.NET
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.
Session management.
ASP.NET 4.0 State Management Improvements – Deep Dive
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.
PHP-II.
Presentation transcript:

Session 10: Managing State

Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax File Application and Session Variables Initializing and Using Application and Session Variables Application and Session Variable Duration Cookies and Cookieless Sessions

What is State Management? First Name Last Name Please enter your logon information: John Submit Chen Web Server Login.aspx Web Server Hello John Chen Greetings.aspx Please enter your logon information: John Submit Chen Hello Greetings.aspx I forget who you are!! First Name Last Name Without State Management With State Management

Types of State Management Server-Side State Management Client-Side State Management Management Application state Information is available to all users of a Web application Cookies Text file stores information to maintain state Session state Information is available only to a user of a specific session The ViewState property Retains values between multiple requests for the same page Database In some cases, use database support to maintain state on your Web site Query strings Information appended to the end of a URL

Server-Side State Management Application state is a global storage mechanism accessible from all pages in the Web application Session state is limited to the current browser session Values are preserved through the use of application and session variables Scalability ASP.NET session is identified by the SessionID string Web Server Client Computer Application and Session variables SessionID

Client-Side State Management Uses cookies to maintain state Persistent cookies Temporary/ Non-persistent cookies Less reliable than server-side state management options User can delete cookies Less secure than server-side state management options Limited amount of information Client-side restrictions on file sizes Web Server Client Computer Cookies

The Global.asax File Only one Global.asax file per Web application Stored in the virtual root of the Web application Used to handle application and session events The Global.asax file is optional

The Global.asax File ( continued ) ASP.NET Web Server Client ASP.NET HTTP Runtime IIS Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_ResolveRequestCache Application_AquireRequestState Application_PreRequestHandlerExecute Application_EndRequest Application_UpdateRequestCache Application_ReleaseRequestState Application_PostRequestHandlerExecute Page execution Request Response

Initializing Application and Session Variables Variables are initialized in Global.asax The Application object shares information among all users of a Web application The Session object stores information for a particular user session Sub Application_Start(s As Object,e As EventArgs) Application("NumberofVisitors") = 0 End Sub Sub Application_Start(s As Object,e As EventArgs) Application("NumberofVisitors") = 0 End Sub

Using Application and Session Variables Set session and application variables Read session and application variables Session("BackColor") = "blue" Application.Lock() Application("NumberOfVisitors") += 1 Application.UnLock() Session("BackColor") = "blue" Application.Lock() Application("NumberOfVisitors") += 1 Application.UnLock() strBgColor = Session("BackColor") lblNbVisitor.Text = Application("NumberOfVisitors") strBgColor = Session("BackColor") lblNbVisitor.Text = Application("NumberOfVisitors")

Application and Session Variable Duration Session variables have a set duration after last access Default is 20 minutes Session duration can be changed in Web.config: Application variables persist until the Application_End event is fired

Creating and Reading Session Cookies You can create and read session cookies by using the Cookies Property of the Response Object and Request Class. Creating a Cookie Reading a Cookie Dim objCookie As New HttpCookie(“myCookie”, “Hello!”) Response.Cookies.Add(objCookie) Dim objCookie As New HttpCookie(“myCookie”, “Hello!”) Response.Cookies.Add(objCookie) Response.Write(Request.Cookies(“myCookie”).Value)

Creating and Reading Persistent Cookies A persistent cookie is similar to a session cookie except that a persistent cookie has a defined expiration date The code below can be used to create a persistent cookie Persistent cookies can be read in the same way as you would a session cookie Dim objCookie As New HttpCookie(“myCookie”, “Hello”) objCookie.Expires = #12/25/2007# Response.Cookies.Add(objCookie) Dim objCookie As New HttpCookie(“myCookie”, “Hello”) objCookie.Expires = #12/25/2007# Response.Cookies.Add(objCookie) To create a persistent cookie, specify the expiration time Response.Write(Request.Cookies(“myCookie”).Value)

Retrieving Information from a Cookie Read the cookie Retrieve values from the cookie lblTime.Text = objCookie.Values("Time") lblTime.ForeColor = System.Drawing.Color.FromName _ (objCookie.Values("ForeColor")) lblTime.BackColor = System.Drawing.Color.FromName _ (objCookie.Values("BackColor")) lblTime.Text = objCookie.Values("Time") lblTime.ForeColor = System.Drawing.Color.FromName _ (objCookie.Values("ForeColor")) lblTime.BackColor = System.Drawing.Color.FromName _ (objCookie.Values("BackColor")) Dim objCookie As HttpCookie = Request.Cookies("myCookie")

Using Cookieless Sessions Each active session is identified and tracked using session IDs Session IDs are communicated across client-server requests using an HTTP cookie or included in the URL Cookieless sessions Session ID information is encoded into URLs Cannot use absolute URLs Most browsers limit the URL size to 255 characters, which limits use of cookieless Session IDs

Setting Up Cookieless Sessions Session state is configured in the section of Web.config Set cookieless = true