State Management.

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,
Current Popular IT I Pertemuan 10 Matakuliah: T0403/Current Popular IT I Tahun: 2008.
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.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
ASP.NET Programming with C# and SQL Server First Edition
1 Chapter Overview Creating User and Computer Objects Maintaining User Accounts Creating User Profiles.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
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.
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
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.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
© 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.
The Web Architecture and ASP.NET. Slide 2 Review of the Web (1) It began with HTTP and HTML, which delivers static Web pages to browsers which would render.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Chapter 6 Server-side Programming: Java Servlets
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.
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:
ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Slide 1 ASP Authentication There are basically three authentication modes Windows Passport Forms There are others through WCF You choose an authentication.
Module 7: Creating a Microsoft ASP.NET Web Application.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Maintaining Application State MIS3502: Application Integration and Evaluation Paul Weinberg Presentation by David Schuff.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
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.
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
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.
©SoftMooreSlide 1 Session Tracking with Servlets.
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.
ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
ASP.NET WEB Applications. ASP.NET  Web application framework developed by Microsoft  Build dynamic data driven web applications and web services  Subset.
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.
ASP.NET Essentials State management, authentication, and Web Services Daniele Pagano Arizona State University.
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.
The need for persistence Consider these examples  Counting the number of “hits” on a website  i.e. how many times does a client load your web page source.
Managing State Chapter 13.
Session Variables and Post Back
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.
ITM 352 Cookies.
ASP.NET Caching.
Session management.
State management & Master Pages in asp.net
HTML5 and Local Storage.
ASP.NET 4.0 State Management Improvements – Deep Dive
Building ASP.NET Applications
© 2016, Mike Murach & Associates, Inc.
PROFILE.
Presentation transcript:

State Management

Lecture Overview Client state management options Cookies Server state management options Application state Session state View state All Web technologies implement state management in some way

Introduction to State Management Remember that ASP.NET (and the Web) is stateless The Web server does not keep track of past client requests Different technologies handle the issue of statement management differently ASP.NET is somewhat unique in this regard But PHP works similarly And so does JSP

JSP State Management Uses a session object like ASP does Session attributes are key value pairs Call setAttribute to set a session variable Call getAttribute to get a session variable We can also use cookies

PHP State Management PHP also uses a session object Call session_start() to create a new variable Use $_SESSION to set session variables

PHP State Management

Types of State Management ASP.NET offers two categories of state management Pure client-side statement management Server-side state management We can use both concurrently

State Management (Issues) Client state management consumes bandwidth and introduces security risks because sensitive data is passed back and forth with each page postback Preserving state on a server can overburden servers We also must consider Web farms and Web gardens

Web Farm A single ASP.NET application is hosted on multiple web servers

Web Garden A single application pool contains multiple worker processes run across multiple CPUs

Client State Management (Types) View state Control state Hidden fields Cookies Query strings

State Management (ViewState) ViewState works in a couple of different ways It’s managed for you automatically via the ASP.NET infrastructure Or you can take control yourself via the ViewState object ViewState only provides state for a single page It won’t work with cross-page postbacks or other page transfers

State Management (ViewState) (auto) Just enable ViewState and the corresponding control retains is value from one postback to the next This happens by default You can disable ViewState at the page level <%@ Page EnableViewState=”false” %> While simple, it does add overhead in terms of page size MaxPageStateFieldLength controls the maximum page size

State Management (ViewState) (manual) ViewState can be set on the server up to the Page_PreRenderComplete event You can save any serializable object to ViewState The information is really just saved in hidden fields

State Management (ControlState) The ControlState property allows you to persist information as serialized data It’s used with custom controls (UserControl) The wiring is not automatic You must program the persisted data each round trip The ControlState data is stored in hidden fields

State Management (Hidden Fields) Use the HiddenField control to store persisted data The data is stored in the Value property It’s simple and requires almost no server resources It’s available from the ToolBox and works much like a text box control

State Management (Cookies) Use to store small amounts of frequently changed data Data is stored on the client’s hard disk A cookie is associated with a particular URL All data is maintained as client cookies Most frequently, cookies store personalization information

Cookie Limitations While simple, cookies have disadvantages A cookie can only be 4096 bytes in size Most browsers restrict the total number of cookies per site Users can refuse to accept cookies so don’t try to use them to store critical information

Cookies Members Use the Response.Cookies collection to reference a cookie Value contains the cookie’s value Expires contains the cookie’s expiration date Cookies can also store multiple values using subkeys Similar to a QueryString It’s possible to restrict cookie scope by setting the Path property to a folder

Server State Management Options Application state Session state Profile properties Database support

Server State Management HttpApplicationState applies to your entire application Application object HttpSessionState applies to the interaction between a user’s browser session and your application Session object Page caching also relates to state management

The Application’s State (Introduction) An instance of the HttpApplicationState object is created the first time a client requests a page from a virtual directory Application state does not work in a Web farm or Web garden scenario Unless we push data to a database It’s volatile – If the server crashes, the data is gone Unless we persist out of process It’s really just a collection of key/value pairs

The HttpApplicationState Class (Members 1) The AllKeys property returns an array of strings containing all of the keys Count gets the number of objects in the collection Item provides read/write access to the collection

The HttpApplicationState Class (Members 2) StaticObjects returns a reference to objects declared in the global.asax file <object> tags with the scope set to Application The Add method adds a new value to the collection The Remove method removes the value associated with a key

The HttpApplicationState Class (Members 3) Lock and Unlock lock the collection, respectively Not an ASP topic but a thread synchronization topic Get returns the value of a collection item The item can be referenced by string key or ordinal index Set store a value corresponding to the specified key The method is thread safe

Application State (Best Practices) Memory to store application state information is permanently allocated You must write explicit code to release that memory So don’t try to persist too much application state information The Cache object, discussed later, provides alternatives to storing application state information

Profile Properties It’s a way to permanently store user-specific data Data is saved to a programmer-defined data store It takes quite a bit of programming The whole thing is unique to windows We will not use profiles in this course

Session State (Introduction) It is used to preserve state for a user’s ‘session’ Session state works in Web farm or Web garden scenarios Use OutProc state server or sql server Session data can be stored in databases such as SQL Server or Oracle making it persistent It’s very powerful and the features have been significantly enhanced in ASP 2.0

Session State (Configuration) The <web.config> file contains a <sessionState> section The entries in this section configure the state client manager

Web.Config <sessionState> <sessionState mode="[Off|InProc|StateServer|SQLServer|Custom]" timeout="number of minutes" cookieName="session identifier cookie name" cookieless= "[true|false|AutoDetect|UseCookies|UseUri|UseDeviceProfile]" regenerateExpiredSessionId="[True|False]" sqlConnectionString="sql connection string" sqlCommandTimeout="number of seconds" allowCustomSqlDatabase="[True|False]" useHostingIdentity="[True|False]" stateConnectionString="tcpip=server:port" stateNetworkTimeout="number of seconds" customProvider="custom provider name"> <providers>...</providers> </sessionState>

Session State Providers (1) Custom – State information is saved in a custom data store Like a database InProc – State information is preserved in the ASP.NET worker process named (aspnet_wp.exe or w3wp.exe) This is the default option Off – Session state is disabled

Session State Providers (2) SQLServer – State data is serialized and stored in an SQL server instance This might be a local or remote SQL Server instance StateServer – State information is stored in a separate state server process (aspnet_state.exe) This process can be run locally or on another machine

Session State Providers (Best Practices) Use an SQL server provider to ensure that session state is preserved Note that there is a performance hit here because the session information is not stored in the page The InProc provider is not perfect The ASP worker process might restart thereby affecting session state

Session State Identifiers Browser sessions are identified with a unique identifier stored in the SessionID property The SessionID is transmitted between the browser and server via A cookie if cookies are enabled The URL if cookies are disabled Set the cookieless attribute to true in the sessionState section of the Web.config file

HttpSessionState (Members 1) CookieMode describes the application’s configuration for cookieless sessions IsCookieless is used to depict whether cookies are used to persist state IsNewSession denotes whether the session was created with this request SessionID gets the unique ID associated with this session Mode denotes the state client manager being used

HttpSessionState (Members 2) Timeout contains the number of minutes to preserve state between requests Abandon sets an internal flag to cancel the current session Add and Remove add or remove an item to the session state Item reads/writes a session state value You can use a string key or ordinal index value