SlideShare a Scribd company logo
BY-Teach4u.in
Lecture Overview
 Client state management options
 Server state management options
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
Types of State Management
 ASP.NET offers two categories of state management
 Pure client-side statement management
 Server-side state management
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
(Introduction)
 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
 While simple, it does add overhead in terms of page size
 MaxPageStateFieldLength controls max size
 You can disable ViewState at the page level
 <%@ Page EnableViewState=”false” %>
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
 See example ViewState.aspx
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
 More later when we create a user control
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
 See example cookies.aspx
State Management
(Query Strings)
 As you know, query strings are just strings appended to
a URL
 All browsers support them and no server resources are
required
State Management
(Query Strings)
 HttpContext.Current.Request.RawURL gets a
URL posted to the server
 Or just use Request.QueryString
 HttpUtility.ParseQueryString breaks a query
string into key / value pairs
 It returns a NameValueCollection
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
 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
 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
Profiles (Enabling)
 Web.config must be modified to enable profiles
 You can then reference with code as follows
Session State (Introduction)
 It is used to preserve state for a user’s ‘session’
 Session state works in Web farm or Web garden
scenarios
 Since the data is persisted in the page
 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
 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 two 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

More Related Content

What's hot

jQuery
jQueryjQuery
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Lena Petsenchuk
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
Mohammed Arif
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web APIhabib_786
 
Intro to Amazon S3
Intro to Amazon S3Intro to Amazon S3
Intro to Amazon S3
Yu Lun Teo
 
Webservices
WebservicesWebservices
Webservices
Gerard Sylvester
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
Amazon Web Services
 
Storage with Amazon S3 and Amazon Glacier
Storage with Amazon S3 and Amazon GlacierStorage with Amazon S3 and Amazon Glacier
Storage with Amazon S3 and Amazon Glacier
Amazon Web Services
 
Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013
Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013
Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013
Amazon Web Services
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
Guddu gupta
 
Dynamodb ppt
Dynamodb pptDynamodb ppt
Dynamodb ppt
Shellychoudhary1
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Javascript
JavascriptJavascript
Javascript
Sun Technlogies
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
State management
State managementState management
State managementIblesoft
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
Deep Patel
 

What's hot (20)

Js ppt
Js pptJs ppt
Js ppt
 
jQuery
jQueryjQuery
jQuery
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Intro to Amazon S3
Intro to Amazon S3Intro to Amazon S3
Intro to Amazon S3
 
Webservices
WebservicesWebservices
Webservices
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
Html Frames
Html FramesHtml Frames
Html Frames
 
Storage with Amazon S3 and Amazon Glacier
Storage with Amazon S3 and Amazon GlacierStorage with Amazon S3 and Amazon Glacier
Storage with Amazon S3 and Amazon Glacier
 
Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013
Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013
Cloud Architectures with AWS Direct Connect (ARC304) | AWS re:Invent 2013
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Dynamodb ppt
Dynamodb pptDynamodb ppt
Dynamodb ppt
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Javascript
JavascriptJavascript
Javascript
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
State management
State managementState management
State management
 
Xml http request
Xml http requestXml http request
Xml http request
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
 

Viewers also liked

State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
Om Vikram Thapa
 
State Management in ASP.NET
State Management in ASP.NETState Management in ASP.NET
State Management in ASP.NET
Shyam Sir
 
State management in ASP .NET
State  management in ASP .NETState  management in ASP .NET
State management
State managementState management
State management
Lalit Kale
 
State management in ASP.net
State  management in ASP.netState  management in ASP.net
State management
State managementState management
State managementIblesoft
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
WCF
WCFWCF
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
Julie Iskander
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewState
Mindfire Solutions
 
Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation
Deepika Chaudhary
 
Master page in ASP . NET
Master page in ASP . NETMaster page in ASP . NET
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
oazabir
 
Master pages ppt
Master pages pptMaster pages ppt
Master pages pptIblesoft
 
Master pages
Master pagesMaster pages
Master pages
teach4uin
 
Asp.net page lifecycle
Asp.net page lifecycleAsp.net page lifecycle
Asp.net page lifecycle
KhademulBasher
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
Abhi Arya
 
JSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTLJSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTL
seleciii44
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
Ilio Catallo
 
Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
Peter R. Egli
 

Viewers also liked (20)

State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
 
State Management in ASP.NET
State Management in ASP.NETState Management in ASP.NET
State Management in ASP.NET
 
State management in ASP .NET
State  management in ASP .NETState  management in ASP .NET
State management in ASP .NET
 
State management
State managementState management
State management
 
State management in ASP.net
State  management in ASP.netState  management in ASP.net
State management in ASP.net
 
State management
State managementState management
State management
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
WCF
WCFWCF
WCF
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewState
 
Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation
 
Master page in ASP . NET
Master page in ASP . NETMaster page in ASP . NET
Master page in ASP . NET
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Master pages ppt
Master pages pptMaster pages ppt
Master pages ppt
 
Master pages
Master pagesMaster pages
Master pages
 
Asp.net page lifecycle
Asp.net page lifecycleAsp.net page lifecycle
Asp.net page lifecycle
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
JSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTLJSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTL
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
 
Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
 

Similar to State management

StateManagement in ASP.Net.ppt
StateManagement in ASP.Net.pptStateManagement in ASP.Net.ppt
StateManagement in ASP.Net.ppt
charusharma165
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
Vivek chan
 
Session viii(state mngtserver)
Session viii(state mngtserver)Session viii(state mngtserver)
Session viii(state mngtserver)
Shrijan Tiwari
 
Session and state management
Session and state managementSession and state management
Session and state management
Paneliya Prince
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07Mani Chaubey
 
Asp.net
Asp.netAsp.net
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
Julie Iskander
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
Vivek chan
 
IEEE KUET SPAC presentation
IEEE KUET SPAC  presentationIEEE KUET SPAC  presentation
IEEE KUET SPAC presentation
ahsanmm
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
Randy Connolly
 
Session viii(state mngtclient)
Session viii(state mngtclient)Session viii(state mngtclient)
Session viii(state mngtclient)
Shrijan Tiwari
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3Neeraj Mathur
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
Akhil Mittal
 
State Management In ASP.NET And ASP.NET MVC
State Management In ASP.NET And ASP.NET MVCState Management In ASP.NET And ASP.NET MVC
State Management In ASP.NET And ASP.NET MVC
jinaldesailive
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08Mani Chaubey
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07Niit Care
 
State management in asp.net
State management in asp.netState management in asp.net

Similar to State management (20)

StateManagement in ASP.Net.ppt
StateManagement in ASP.Net.pptStateManagement in ASP.Net.ppt
StateManagement in ASP.Net.ppt
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Session viii(state mngtserver)
Session viii(state mngtserver)Session viii(state mngtserver)
Session viii(state mngtserver)
 
Session and state management
Session and state managementSession and state management
Session and state management
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Asp.net
Asp.netAsp.net
Asp.net
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
 
IEEE KUET SPAC presentation
IEEE KUET SPAC  presentationIEEE KUET SPAC  presentation
IEEE KUET SPAC presentation
 
2310 b 14
2310 b 142310 b 14
2310 b 14
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Session viii(state mngtclient)
Session viii(state mngtclient)Session viii(state mngtclient)
Session viii(state mngtclient)
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
State Management In ASP.NET And ASP.NET MVC
State Management In ASP.NET And ASP.NET MVCState Management In ASP.NET And ASP.NET MVC
State Management In ASP.NET And ASP.NET MVC
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
State management in asp.net
State management in asp.netState management in asp.net
State management in asp.net
 

More from teach4uin

Controls
ControlsControls
Controls
teach4uin
 
validation
validationvalidation
validation
teach4uin
 
validation
validationvalidation
validation
teach4uin
 
.Net framework
.Net framework.Net framework
.Net framework
teach4uin
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
teach4uin
 
Css1
Css1Css1
Css1
teach4uin
 
Code model
Code modelCode model
Code model
teach4uin
 
Asp db
Asp dbAsp db
Asp db
teach4uin
 
security configuration
security configurationsecurity configuration
security configuration
teach4uin
 
static dynamic html tags
 static dynamic html tags static dynamic html tags
static dynamic html tags
teach4uin
 
static dynamic html tags
static dynamic html tagsstatic dynamic html tags
static dynamic html tags
teach4uin
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
teach4uin
 
.Net overview
.Net overview.Net overview
.Net overview
teach4uin
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
teach4uin
 
enums
enumsenums
enums
teach4uin
 
memory
memorymemory
memory
teach4uin
 
array
arrayarray
array
teach4uin
 
storage clas
storage classtorage clas
storage clas
teach4uin
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
teach4uin
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
teach4uin
 

More from teach4uin (20)

Controls
ControlsControls
Controls
 
validation
validationvalidation
validation
 
validation
validationvalidation
validation
 
.Net framework
.Net framework.Net framework
.Net framework
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Css1
Css1Css1
Css1
 
Code model
Code modelCode model
Code model
 
Asp db
Asp dbAsp db
Asp db
 
security configuration
security configurationsecurity configuration
security configuration
 
static dynamic html tags
 static dynamic html tags static dynamic html tags
static dynamic html tags
 
static dynamic html tags
static dynamic html tagsstatic dynamic html tags
static dynamic html tags
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
 
.Net overview
.Net overview.Net overview
.Net overview
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
 
enums
enumsenums
enums
 
memory
memorymemory
memory
 
array
arrayarray
array
 
storage clas
storage classtorage clas
storage clas
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 

Recently uploaded

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

State management

  • 2. Lecture Overview  Client state management options  Server state management options
  • 3. 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
  • 4. Types of State Management  ASP.NET offers two categories of state management  Pure client-side statement management  Server-side state management
  • 5. 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
  • 6. Web Farm  A single ASP.NET application is hosted on multiple web servers
  • 7. Web Garden  A single application pool contains multiple worker processes run across multiple CPUs
  • 8. Client State Management (Introduction)  View state  Control state  Hidden fields  Cookies  Query strings
  • 9. 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
  • 10. State Management (ViewState) (auto)  Just enable ViewState and the corresponding control retains is value from one postback to the next  This happens by default  While simple, it does add overhead in terms of page size  MaxPageStateFieldLength controls max size  You can disable ViewState at the page level  <%@ Page EnableViewState=”false” %>
  • 11. 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  See example ViewState.aspx
  • 12. 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  More later when we create a user control
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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  See example cookies.aspx
  • 17. State Management (Query Strings)  As you know, query strings are just strings appended to a URL  All browsers support them and no server resources are required
  • 18. State Management (Query Strings)  HttpContext.Current.Request.RawURL gets a URL posted to the server  Or just use Request.QueryString  HttpUtility.ParseQueryString breaks a query string into key / value pairs  It returns a NameValueCollection
  • 19. Server State Management Options  Application state  Session state  Profile properties  Database support
  • 20. 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
  • 21. 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  It’s really just a collection of key/value pairs
  • 22. 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
  • 23. 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
  • 24. The HttpApplicationState Class (Members 3)  Lock and Unlock lock the collection, respectively  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
  • 25. 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
  • 26. 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
  • 27. Profiles (Enabling)  Web.config must be modified to enable profiles  You can then reference with code as follows
  • 28. Session State (Introduction)  It is used to preserve state for a user’s ‘session’  Session state works in Web farm or Web garden scenarios  Since the data is persisted in the page  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
  • 29. Session State (Configuration)  The <web.config> file contains a <sessionState> section  The entries in this section configure the state client manager
  • 30. 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>
  • 31. Session State Providers (1)  Custom – State information is saved in a custom data store  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
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. HttpSessionState (Members 2)  Timeout contains the number of minutes to preserve state between two 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