State Management. What is State management Why State management ViewState QueryString Cookies.

Slides:



Advertisements
Similar presentations
PHP I.
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.
PHP (2) – Functions, Arrays, Databases, and sessions.
An Overview of Database Access on the Web An Overview of Database Access on the Web Using ASP and Microsoft Database Technology Sheffield Hallam University.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
ASP.NET Programming with C# and SQL Server First Edition
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
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.
 A cookie is a piece of text that a Web server can store on a user's hard disk.  Cookie data is simply name-value pairs stored on your hard disk by.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Tutorial 10 Adding Spry Elements and Database Functionality Dreamweaver CS3 Tutorial 101.
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.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Managing State.
M1G Introduction to Database Development 6. Building Applications.
Chapter 8 Cookies And Security JavaScript, Third Edition.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University
Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types.
Effective Security in ASP.Net Applications Jatin Sharma: Summer 2005.
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.
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.
Module 7: Creating a Microsoft ASP.NET Web Application.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
State Management. Content State Management View State Cross-Page Posting Query String Cookies Session State Application State Muzaffer DOĞAN - Anadolu.
Web Database Programming Week 7 Session Management & Authentication.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
CIS 451: Cookies Dr. Ralph D. Westfall February, 2009.
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.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
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.
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.
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 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
Managing State Chapter 13.
Running a Forms Developer Application
Session Variables and Post Back
State Management.
Internet Programming Chapter 9: State Management in ASP.NET
PHP / MySQL Introduction
The Request & Response object
Session management.
State management & Master Pages in asp.net
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.
HTML5 and Local Storage.
ASP.NET 4.0 State Management Improvements – Deep Dive
Building ASP.NET Applications
Presentation transcript:

State Management

What is State management Why State management ViewState QueryString Cookies

State management In a window program the user interacts with the continuously running application A portion of memory on the desktop computer is allocated to store the current set of working information In Web application the story is different

A professional ASP.NET site might look like a continuously running application Web application uses a disconnected access pattern

Why State Management-Disconnected access pattern Client Web Server Connect & request a page Response & info abandoned Web servers discard the client information

Web Application handles of thousands of requests Web Server Client 1 Client 2 Client 3 Client 4 Client 5 Client 6

The clients can be connected to the web server only for a few seconds Web server needs to serve thousands of request To retain the working information the user needs to take special measure

Viewstate QueryString Cookies

Viewstate It allows the controls to retain their state Viewstate information is stored in the hidden field The hidden field holds the information in a crazy string format that is non-readable and it changes dynamically everytime the informations in the control is changed It is the first option for state management

ViewState Example :Counter Dim count As Integer If Me.ViewState("count") = Nothing Then count = 1 Else count = CType(Me.ViewState("count"), Integer) + 1 End If Me.ViewState("count") = count Label1.Text = count.ToString()

Transferring information One of the limitations of the viewstate is that it is tightly bound to a page Page navigation makes the data to get lost One common approach that we use is to pass information using the query string Used in search engines ganic

QueryString The querystring is a portion of the URL followed after the ? In the above example, it defines a single variable named ask which contains the string “organic” It is a useful technique in the database applications where you present a list of details that correspond to records in the db

QueryString The user can select an item and be forwarded to a detailed information page This page can receive the unique ID that identifies the record from the sending page and look up for information from the db Example Amazon site Response.redirect(“newpage.aspx?recordID=10”)

Querystring example

if (ListBox1.SelectedIndex == -1) { Label1.Text = "U must select a item"; } else { string qs = "Default.aspx?"; qs += "Item=" + ListBox1.SelectedItem.Text; Response.Redirect(qs); }

QueryString The new page can receive the values from the querystring with Request object Dim ID as String=Request.QuerySting(“recordID”)

QueryString limitation Information is limited to simple string; which contain legal URL characters Information is clearly visible to the user (eavesdrop) Less security over the Internet Browsers impose restriction on the length of the Querystring,hence a large string cannot be placed

Cookies Custom cookies provide another way that you can store information Cookies are small files that are stored on the hard drive Cookies work transparently (ie) without the user being aware that information are stored Long term storage

Drawbacks Suffer with the limitation of the string length Information's are easily readable by the user and less security

Using Cookies Use the namespace Using System.Net Both the Request and Response objects provide the cookie collection The cookies are retrieved from the Request object and cookies are set using the Response object To set a cookie just create System.Net.HttpCookie object

Creating cookies Set a value in it Add it to the cookies collection Cookie=new HttpCookie(Preferences”) Cookie(“LanguagePref”)=English Response.cookies.add(Cookie)

Setting the expiry time for cookies A cookie normally persists until the user closes the browser and will be sent with the request.To create a long lived cookie set the expiry date This cookie lives for 1 year Cookie.Expires =DateTime.Now.AddYears(1)

Check for the existence of cookies Private Sub Page_Load(sender as Object,e as EventArgs) { dim cookie As HttpCookie =Request.Cookies(“Preferences”) if cookie Is Nothing Then LabelWelcome.Text=”Unkown Customer” else LabelWelcomet.Text=”Cookie found” LabelWelcome.Text=”Cookie found,” & Cookie(“Name”) End If End Sub

Cookies storing and retrieving Private sub cmdstore_Click(sender as object,e as EventArgs) Dim cookie as HttpCookie=Request.Cookies(“Preferences”) If cookie is Nothing Then Cookie=new HttpCookie(“Preferences”) End If Cookie(“Name”)=TextName.Text Cookie.Expires=DateTime.AddYears(1) Response.Cookies.Add(Cookie) LabelWelcome.Text=”New customer” & Cookie(“Name”)

Session State Application need to access complex information such as Datasets which cannot be persisted by Querystring or cookies In these situations we use the ASP.NET built in facility Session state facility It is one of the premiere feature It allows you to store any type of data on the server

Session State The information is protected with a unique session. Every client who access the application is created with a unique session

Session tracking ASP.NET tracks each session using a 120 bit identifier. It uses a special algorithm to track the value No hackers can guess the session ID This ID is the piece of information transferred between the client and the server

Session Information I Session ID Session Information II Session ID User presents the Session-ID Matches the Session ID and Returns the Session information

Session State -Storing values in Session State Syntax Session(“Session variable”) =Datasource Example Session(“ds)=dsinfo

Session State -Retrieving values from Session Syntax Temporary variable =Ctype(Session(“Session Variable”),DataSet) Example ds=CType(Session(“ds”),DataSet)

How can Session State be lost If the user closes the browser If the session is timed out If the programmer ends the session in the program If the user access the same page through different browser

Example Restrict only the signed in users to enter the appropriate page

Session State configuration Session State is configured through Web.config file in the ASP.NET It allows to set most of the options such as Session State mode and timeout..

CookieLess You can set the cookieless setting to true or false  cookieless=”false”

Session State When set to true,the session ID will automatically be inserted into the URL ASP.NET on receiving the request it collects the session information

Timeout Another Session State settings in the web.config file is timeout It specifes the number of minutes that ASP.NET will wait,without receiving the Request,before it discards the session  timout=”20” 

Mode Off: this setting disables state management for every Page in the application StateServer:Separate windows service outside ASP.NET  Set manual setting to start on and off SqlServer:It stores the session information in the databases available in the SQL Server

Application State It stores global objects that can be used by any client A common example is the global counter that tracks how many times an operation has been performed by all clients

Global counter Protected Sub Page_Load(sender as Object,e as EventArgs) Application.Lock( ) Dim count as Integer =CType(Application(“Hit”,Integer)) Count+=1 Application(“Hit”)=count Application.Unlock( ) Label1.text=Count.ToString( ) End Sub