State Management. Agenda View state Application cache Session state ProfilesCookies.

Slides:



Advertisements
Similar presentations
Malek Kemmou Technology Architect, Application Platform Microsoft Middle East and Africa Overview of ASP.NET 2.0.
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.
Advanced Performance Techniques in ASP.NET 2.0 William Zhang, Ph.D. Senior Consultant Microsoft Consulting Services.
Caching MacDonald Ch. 26 MIS 424 MIS 424 Professor Sandvig Professor Sandvig.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
Chapter 9 Web Applications Yingcai Xiao. Enterprise Application Architectures.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Membership, Role Manager and Profile Membership, Role Manager and Profile Matt Gibbs ASP.NET Development Manager.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 9 Web Applications Yingcai Xiao. Enterprise Application Architectures.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Web Forms. Agenda Web forms Web controls Code separation Dynamic compilation System.Web.UI.Page User controls.
Philip Wolfe Senior Consultant Sogeti Session 3 - Leveraging Data in ASP.NET 2.0 (Level 200)
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.
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Welcome  30 Question & 30 Minutes  Question Will Move Automatically After 1 Min Your Exam Start Now Lecturer : Zalak Thakrar.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
Microsoft ASP.NET: An Overview of Caching. 2 Overview  Introduction to ASP.NET caching  Output caching  Data caching  Difference between Data Caching.
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.
State Management. What is State management Why State management ViewState QueryString Cookies.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
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.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
Effective Security in ASP.Net Applications Jatin Sharma: Summer 2005.
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.
State Management. Agenda View state Application cache Session state ProfilesCookies.
WEB320 Migrating ASP.NET 1.x Applications to ASP.NET 2.0 Stefan Schackow Program Manager Web Platform and Tools Team Microsoft Corporation.
BIT 285: ( Web) Application Programming Lecture 06: Thursday, January 22, 2015 Page Object, The Lifetime of a Web Application, Application State and Session.
ASP.NET 2.0: A Look Inside Membership, Role Management, and Profiles in ASP.NET 2.0 Sam Spencer Program Manager Microsoft – Web Platform & Tools DEV312.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
A Lap Around New Enhancements for Web Developers in Visual Studio 2005 Alexander Holy Developer Evangelist, Microsoft EMEA
ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC.
Session, TempData, Cache Andres Käver, IT Kolledž
Personalizing Web Sites Nasrullah. Understanding Profile The ASP.NET application service that enables you to store and retrieve information about users.
Security. Agenda ASP.NET security basics AuthenticationAuthorization Security principals Forms authentication Membership service Login controls Role Management.
PLACING ORDERS- SHOPPPING CARTS. Introduction There are several stages to the order process, starting with an order page, which allows customers to add.
ASP.NET 2.0 Security Alex Mackman CM Group Ltd
Alexey Polovinkin Post graduate student, CMC department.
CHAPTER 9 File Storage Shared Preferences SQLite.
Developing Custom ASP.NET Providers For Membership And Role Manager Stefan Schackow PRS404 Program Manager – Web Platform and Tools Microsoft Corporation.
ASP.NET Essentials State management, authentication, and Web Services Daniele Pagano Arizona State University.
ASP.NET Architecture Mike Taulty Developer & Platform Group Microsoft Ltd
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
Vinod Unny Enterprise InfoTech Microsoft Regional Director, North India
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Office 365 Development July 2014.
Building Web Applications with Microsoft ASP
Session Variables and Post Back
State Management.
Chapter 9 Web Applications
ISC440: Web Programming 2 Server-side Scripting PHP 3
Session management.
HTML5 and Local Storage.
ASP.NET 4.0 State Management Improvements – Deep Dive
© 2016, Mike Murach & Associates, Inc.
PROFILE.
Microsoft Dynamics.
Presentation transcript:

State Management

Agenda View state Application cache Session state ProfilesCookies

View State Mechanism for persisting relatively small pieces of data across postbacks Used by pages and controls to persist state Also available to you for persisting state Relies on hidden input field (__VIEWSTATE) Accessed through ViewState property Tamper-proof; optionally encryptable

Reading and Writing View State // Write the price of an item to view state ViewState["Price"] = price; // Read the price back following a postback decimal price = (decimal) ViewState["Price"];

View State and Data Types What data types can you store in view state? Primitive types (strings, integers, etc.) Types accompanied by type converters Serializable types (types compatible with BinaryFormatter) System.Web.UI.LosFormatter performs serialization and deserialization Optimized for compact storage of strings, integers, booleans, arrays, and hash tables

Application Cache Intelligent in-memory data store Item prioritization and automatic eviction Time-based expiration and cache dependencies Cache removal callbacks Application scope (available to all users) Accessed through Cache property Page.Cache - ASPX HttpContext.Cache - Global.asax Great tool for enhancing performance

Using the Application Cache // Write a Hashtable containing stock prices to the cache Hashtable stocks = new Hashtable (); stocks.Add ("AMZN", 10.00m); stocks.Add ("INTC", 20.00m); stocks.Add ("MSFT", 30.00m); Cache.Insert ("Stocks", stocks);. // Fetch the price of Microsoft stock Hashtable stocks = (Hashtable) Cache["Stocks"]; if (stocks != null) // Important! decimal msft = (decimal) stocks["MSFT"];. // Remove the Hashtable from the cache Cache.Remove ("Stocks");

Cache.Insert public void Insert ( string key, // Key that identifies item object value, // The item itself CacheDependency dependencies, // Cache dependencies (if any) DateTime absoluteExpiration, // When should item expire (absolute)? TimeSpan slidingExpiration, // When should item expire (sliding)? CacheItemPriority priority, // Item's priority relative to other items CacheItemRemovedCallback onRemoveCallback // Removal callback delegate );

Temporal Expiration Cache.Insert ("Stocks", stocks, null, DateTime.Now.AddMinutes (5), Cache.NoSlidingExpiration); Cache.Insert ("Stocks", stocks, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes (5)); Expire after 5 minutes Expire if 5 minutes elapse without the item being retrieved from the cache

Cache Dependencies Cache.Insert ("Stocks", stocks, new CacheDependency (Server.MapPath ("Stocks.xml"))); Cache.Insert ("Stocks", stocks, new SqlCacheDependency ("Stocks", "Prices")); Expire if and when Stocks.xml changes Expire if and when the "Stocks" database's "Prices" table changes

Application Cache

Session State Read/write per-user data store Accessed through Session property Page.Session - ASPX HttpApplication.Session - Global.asax Provider-based for flexible data storage In-process (default) State server process SQL Server Cookied or cookieless

Using Session State // Write a ShoppingCart object to session state ShoppingCart cart = new ShoppingCart (); Session["Cart"] = cart;. // Read this user's ShoppingCart from session state ShoppingCart cart = (ShoppingCart) Session["Cart"];. // Remove this user's ShoppingCart from session state Session.Remove ("Cart");

In-Process Session State... Web Server ASP.NET Session State Session state stored inside ASP.NET's worker process

State Server Session State <sessionState mode="StateServer" stateConnectionString="tcpip= :42424" />... Web Server ASP.NET State Server ASP.NET state service (aspnet_- state.exe) aspnet_state Process aspnet_state Process

SQL Server Session State <sessionState mode="SQLServer" sqlConnectionString="server=orion;integrated security=true" />... Web Server ASP.NET Database Server ASPState Database ASPState Database Created with InstallSqlState.sql or InstallPersistSql- State.sql

Session Events Session_Start event signals new session Session_End event signals end of session Process with handlers in Global.asax void Session_Start () { // Create a shopping cart and store it in session state // each time a new session is started Session["Cart"] = new ShoppingCart (); } void Session_End () { // Do any cleanup here when session ends }

Session Time-Outs Sessions end when predetermined time period elapses without any requests from session's owner Default time-out = 20 minutes Time-out can be changed in Web.config...

Profile Service Stores per-user data persistently Strongly typed access (unlike session state) On-demand lookup (unlike session state) Long-lived (unlike session state) Supports authenticated and anonymous users Accessed through dynamically compiled HttpProfileBase derivatives (HttpProfile) Provider-based for flexible data storage

Profile Schema Profiles Profile Data Stores SQL Server Other Data Stores HttpProfileBase HttpProfile (Autogenerated HttpProfileBase-Derivative) HttpProfile (Autogenerated HttpProfileBase-Derivative) AccessProfileProvider Other Providers Profile Providers SqlProfileProvider Access HttpProfile (Autogenerated HttpProfileBase-Derivative) HttpProfile (Autogenerated HttpProfileBase-Derivative)

Defining a Profile

Using a Profile // Increment the current user's post count Profile.Posts = Profile.Posts + 1; // Update the current user's last post date Profile.LastPost = DateTime.Now;

How Profiles Work public partial class page_aspx : System.Web.UI.Page {... protected ASP.HttpProfile Profile { get { return ((ASP.HttpProfile)(this.Context.Profile)); } }... } Autogenerated class representing the page Autogenerated class derived from HttpProfileBase Profile property included in autogenerated page class

Profile Groups Properties can be grouped element defines groups element defines groups......

Defining a Profile Group

Accessing a Profile Group // Increment the current user's post count Profile.Forums.Posts = Profile.Forums.Posts + 1; // Update the current user's last post date Profile.Forums.LastPost = DateTime.Now;

Custom Data Types Profiles support base types String, Int32, Int64, DateTime, Decimal, etc. Profiles also support custom types Use type attribute to specify type Use serializeAs attribute to specify serialization mode: Binary, Xml (default), or String serializeAs="Binary" types must be serializable serializeAs="String" types need type converters

Using a Custom Data Type

Anonymous User Profiles By default, profiles aren't available for anonymous (unauthenticated) users Data keyed by authenticated user IDs Anonymous profiles can be enabled Step 1: Enable anonymous identification Step 2: Specify which profile properties are available to anonymous users Data keyed by user anonymous IDs

Profiles for Anonymous Users

Profile Providers Profile service is provider-based Beta 1 ships with two providers AccessProfileProvider (Access)* SqlProfileProvider (SQL Server) Use custom providers to add support for other data stores * Will be replaced by SQL Express provider in beta 2

Using the SQL Server Provider

Profiles

Cookies Mechanism for persisting textual data Described in RFC 2109 For relatively small pieces of data HttpCookie class encapsulates cookies HttpRequest.Cookies collection enables cookies to be read from requests HttpResponse.Cookies collection enables cookies to be written to responses

HttpCookie Properties NameDescription NameCookie name (e.g., "UserName=Jeffpro") ValueCookie value (e.g., "UserName=Jeffpro") ValuesCollection of cookie values (multivalue cookies only) HasKeysTrue if cookie contains multiple values DomainDomain to transmit cookie to ExpiresCookie's expiration date and time SecureTrue if cookie should only be transmitted over HTTPS PathPath to transmit cookie to

Creating a Cookie HttpCookie cookie = new HttpCookie ("UserName", "Jeffpro"); Response.Cookies.Add (cookie); Cookie name Cookie value

Reading a Cookie HttpCookie cookie = Request.Cookies["UserName"]; if (cookie != null) { string username = cookie.Value; // "Jeffpro"... }

© Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.