SlideShare una empresa de Scribd logo
1 de 75
ASP.NET
State management
1Shyam N. Chawda 9374928879
Welcome my dear students2
Shyam N. Chawda 9374928879
IsPostBack Property
Page class’s property , which you can use to detect whether the
page has already been post back to server.
True/False
True – Yes 2nd time
For View Effects
Take Dropdown and Add items in the form load
Take Button
3
Shyam N. Chawda 9374928879
What is State management?
HTTP protocol is a stateless protocol.
Web server does not have any idea about the
requests from where they coming
On each request web pages are created and
destroyed.
4
Shyam N. Chawda 9374928879
What is State management?
A new instance of the Web page class is created
each time the page is posted to the server.
All information associated with the page and the
controls on the page would be lost with each
round trip.
5
Shyam N. Chawda 9374928879
What is State management?
So, how do we make web pages which will
remember about the user ?
6
Shyam N. Chawda 9374928879
What is State management?
Client-Based
Server-Based
7
Shyam N. Chawda 9374928879
What is State management?
Client-Based
8
Shyam N. Chawda 9374928879
Shyam N. Chawda 93749288799
Client
side
View
state
Cookies
Query
strings
Hidden
fields
What is State management?
Server-Based
10
Shyam N. Chawda 9374928879
Shyam N. Chawda 937492887911
Server
side
Application
state
Database
Session
state
Client Side state management
Query String
For understand it you must aware about Request and
Response object
12
Shyam N. Chawda 9374928879
Response Object
You can use this class to inject text into the page, jump to
other page etc.
Write
Redirect
13
Shyam N. Chawda 9374928879
Request Object
Provides access to the current page request, including the
request headers, cookies, query string, and so on.
IsSecureConnection
Checks to see whether you are communicating via an
HTTPS secure protocol or not.
14
Shyam N. Chawda 9374928879
Request Object
Request.Browser.Browser
Request.QueryString()
15
Shyam N. Chawda 9374928879
Query string
Information that is appended to the end of a page URL.
You can use a query string to submit data back to your
page or to another page through the URL.
Query strings provide a simple but limited way to maintain
state information.
16
Shyam N. Chawda 9374928879
Query string
For example in first page you collect information about your client,
name and use this information in your second page.
Take 2 forms
Take 1 textbox and one button
Response.Redirect("Page2.aspx?Name=" & TextBox1.Text
Request.QueryString("Name")
17
Shyam N. Chawda 9374928879
Query string
Response.redirect(“Formname?” &
qry);
Response.redirect(“Formname?name=”
& value);
18
Shyam N. Chawda 9374928879
Query string
Advantages
No server resources are required
Widespread support Almost all browsers and client
devices support using query strings to pass values.
Simple implementation
19
Shyam N. Chawda 9374928879
Query string
Disadvantages
Potential security risks
The information in the query string is directly visible to the
user via the browser's user interface.
Limited capacity Some browsers and client devices
impose a 2083-character limit on the length of URLs.
20
Shyam N. Chawda 9374928879
More than one Query string
Using &
Dim str As String
str = "PageRequest.aspx?Name=" & TextBox1.Text & "&" &
"Lname=" & TextBox2.Text
21
Shyam N. Chawda 9374928879
View State
View State is used to remember controls state when
page is posted back to server.
You can store page-specific information
22
Shyam N. Chawda 9374928879
View State
The view state is implemented with a hidden form field
called _VIEWSTATE, which is automatically created in
every Web page.
When page is created on web sever this hidden control is
populate with state of the controls and when page is posted
back to server this information is retrieved and assigned to
controls.
23
Shyam N. Chawda 9374928879
View State
24
Shyam N. Chawda 9374928879
View State
Go View Source
Each control on a Web Forms page has a
ViewState property.
Take example of DropdownList
Set Property EnableViewState=True
Take also one button
25
Shyam N. Chawda 9374928879
View State
<%@ Page Language="VB" EnableViewState="false"
AutoEventWireup="false" CodeFile="frmViewState.aspx.vb"
Inherits="frmViewState" %>
By default true.
So, even if it’s all the controls has set the
property Enableviewstate=True but they are not
working.
26
Shyam N. Chawda 9374928879
View State
Take 2 Buttons and 1 TextBox
Take one variable before all the coding
Assign that variable in one button click and display in
the textbox
Click and 2nd button and write the same logic.
27
Shyam N. Chawda 9374928879
View State
no = 5
ViewState("No") = no
TextBox1.Text = ViewState ("No")
28
Shyam N. Chawda 9374928879
Shyam N. Chawda 937492887929
So,Moral of the story about ViewState
EnableViewState property for each control
EnableviewState attribute of the @Page (Page directive)
View source _ViewState
Store value using ViewState(Key)
View State
Advantages
No server resources are required
Simple implementation
View state does not require any custom programming to
use. It is on by default to maintain state data on controls.
30
Shyam N. Chawda 9374928879
View State
Enhanced security features
The values in view state are hashed, compressed, and
encoded for Unicode implementations, which provides more
security than using hidden fields.
31
Shyam N. Chawda 9374928879
View State
Disadvantages
Performance considerations
Storing large values can cause the page to slow down when
users display it and when they post it.
This is especially relevant for mobile devices, where
bandwidth is often a limitation.
32
Shyam N. Chawda 9374928879
View State
Device limitations
Mobile devices might not have the memory capacity to store
a large amount of view-state data.
33
Shyam N. Chawda 9374928879
Hidden Fields
You can store page-specific information.
This control is not visible when the application is viewed in
the browser.
Storage area for page specific.
You must submit your pages to the server using the HTTP
POST method
34
Shyam N. Chawda 9374928879
Shyam N. Chawda 937492887935
Hidden Fields
Does not render in a Web browser.
However, you can set the properties of the hidden field.
A hidden field stores a single variable in its value property
and must be explicitly added to the page.
36
Shyam N. Chawda 9374928879
Hidden Fields
Advantages
No server resources are required
Widespread support
Almost all browsers and client devices support forms with
hidden fields.
37
Shyam N. Chawda 9374928879
Hidden Fields
Simple implementation
Hidden fields are standard HTML controls that require no
complex programming logic.
38
Shyam N. Chawda 9374928879
Hidden Fields
Disadvantages
Potential security risks
The information in the hidden field can be seen if the page
output source is viewed directly, creating a potential
security issue.
Encrypt and decrypt the contents of a hidden field, but
doing so requires extra coding and overhead.
39
Shyam N. Chawda 9374928879
Hidden Fields
Performance considerations
Because hidden fields are stored in the page itself, storing
large values can cause the page to slow
Storage limitations
If the amount of data in a hidden field becomes very large,
some proxies and firewalls will prevent access to the page
that contains them.
40
Shyam N. Chawda 9374928879
Cookies
A Cookie is a small text file that the browser creates and
stores on the hard drive of your machine.
Cookie is just one or more pieces of information stored as
text strings.
41
Shyam N. Chawda 9374928879
Cookies
Cookies are useful for storing small amounts of frequently
changed information on the client.
The cookie contains information the Web application can
read whenever the user visits the site.
Cookies are associated with a Web site, not with a specific
page, so the browser and server will exchange cookie
information.
42
Shyam N. Chawda 9374928879
Cookies
Good example
1. A site conducting a poll might use a cookie simply as a
Boolean value to indicate whether a user's browser has
already participated in voting so that the user cannot
vote twice.
2. Ebay assigns you an ID
43
Shyam N. Chawda 9374928879
Cookies
Good example
1. A site conducting a poll might use a cookie simply as a
Boolean value to indicate whether a user's browser has
already participated in voting so that the user cannot
vote twice.
2. Ebay assigns you an ID
44
Shyam N. Chawda 9374928879
Cookies
Cookies can either be temporary or persistent.
When creating a cookie, you specify a Name and Value.
Each cookie must have a unique name.
You can also set a cookie's date and time expiration.
45
Shyam N. Chawda 9374928879
Cookies
If you do not set the cookie's expiration, the cookie is
created but it is not stored on the user's hard disk.
46
Shyam N. Chawda 9374928879
Sets - Cookies
Dim aCookie As New HttpCookie("lastVisit")
aCookie.Values("Name") = txtName.Text
aCookie.Values("Dt") =
DateTime.Now.ToString
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
47
Shyam N. Chawda 9374928879
Gets - Cookies
If Not Request.Cookies("lastVisit") Is Nothing Then
txtNameR.Text =
Request.Cookies("lastVisit").Values("Name").ToStri
ng
txtDateR.Text =
Request.Cookies("lastVisit").Values("Dt").ToString
End if
48
Shyam N. Chawda 9374928879
Cookies
Advantages
No server resources are required
Simplicity
The cookie is a lightweight, text-based structure.
49
Shyam N. Chawda 9374928879
Cookies
Advantages
Data persistence
Although the durability of the cookie on a client computer is
subject to cookie expiration processes on the client and user
intervention, cookies are generally the most durable form of data
persistence on the client.
50
Shyam N. Chawda 9374928879
Cookies
Disadvantages
Size limitations
Most browsers place a 4096-byte limit on the size of a cookie,
although support for 8192-byte
51
Shyam N. Chawda 9374928879
Cookies
User-configured refusal
Some users disable their browser or client device's ability to
receive cookies, thereby limiting this functionality.
52
Shyam N. Chawda 9374928879
Cookies
Potential security risks
Users can manipulate cookies on their computer, which can
potentially cause a security risk or cause the application that is
dependent on the cookie to fail.
53
Shyam N. Chawda 9374928879
What is State Management?
Server-Based
Application state
Session state
Database
54
Shyam N. Chawda 9374928879
Application State
Storing application wide-specific information such as objects
and variables.
All information stored in the application state is shared
among all the pages of the Web application by using the
HttpApplicationState class.
55
Shyam N. Chawda 9374928879
Application State
The ideal data to insert into application state variables is
data that is shared by multiple sessions and does not
change often.
56
Shyam N. Chawda 9374928879
Application State
Goto Global.asax
Find Counter : Session_Start
Application(“Cnt”)= Application(“Cnt”)= +1
57
Shyam N. Chawda 9374928879
Application State
Application("Message") = "Welcome to the LJ”
Application("Cnt") = 0
Sub Session_Start(ByVal sender As Object,
ByVal e As EventArgs)
Application("Cnt") = Application("Cnt") + 1
58
Shyam N. Chawda 9374928879
Application State
Advantages
Simple implementation
Application state is easy to use
59
Shyam N. Chawda 9374928879
Application State
Application scope
Because application state is accessible to all pages in an
application, storing information in application state can
mean keeping only a single copy of the information
60
Shyam N. Chawda 9374928879
Application State
Disadvantages
Limited durability of data
Because global data that is stored in application state is
volatile, it will be lost if the Web server process containing it
is destroyed, such as from a server crash, upgrade, or
shutdown.
61
Shyam N. Chawda 9374928879
Application State
Resource requirements
Application state requires server memory, which can affect
the performance of the server as well as the scalability of
the application.
62
Shyam N. Chawda 9374928879
Session State
Use when you are storing short-lived information that is
specific to an individual session and security is an issue.
Do not store large quantities of information in session state.
63
Shyam N. Chawda 9374928879
Session State
Session("FirstName") = FirstNameTextBox.Text
Session("LastName") = LastNameTextBox.Text
Each active ASP.NET session is identified and tracked using
a 120-bit.$
SessionID values are generated using an algorithm
64
Shyam N. Chawda 9374928879
Session State
The scope of session state is limited to the current browser
session.
If different users are accessing a Web application, each will
have a different session state.
Create Login Form
65
Shyam N. Chawda 9374928879
Session State
The scope of session state is limited to the current browser
session.
If different users are accessing a Web application, each will
have a different session state.
Create Login Form
66
Shyam N. Chawda 9374928879
Session State
Advantages
Simple implementation
Data persistence
Data placed in session-state variables can be preserved
through Internet Information Services (IIS) restarts and
worker-process restarts without losing session data because
the data is stored in another process space.
67
Shyam N. Chawda 9374928879
Session State
Cookieless support
Session state works with browsers that do not support HTTP
cookies, although session state is most commonly used with
cookies to provide user identification facilities to a Web
application.
68
Shyam N. Chawda 9374928879
Session State
Cookieless support
Session state works with browsers that do not support HTTP
cookies, although session state is most commonly used with
cookies to provide user identification facilities to a Web
application.
69
Shyam N. Chawda 9374928879
Session State
Disadvantage
Performance considerations
Session-state variables stay in memory until they are either removed
or replaced.
70
Shyam N. Chawda 9374928879
Database
Database enables you to store large amount of information
pertaining to state in your Web application.
Sometimes users continually query the database by using
the unique ID, you can save it in the database for use
across multiple request for the pages in your site.
71
Shyam N. Chawda 9374928879
Database
Advantages
Security
Access to databases requires rigorous authentication and
authorization.
72
Shyam N. Chawda 9374928879
Database
Storage capacity
You can store as much information as you like in a
database.
Data persistence
Database information can be stored as long as you like, and
it is not subject to the availability of the Web server.
73
Shyam N. Chawda 9374928879
Database
Disadvantage
Complexity
Using a database to support state management requires
that the hardware and software configurations be more
complex.
74
Shyam N. Chawda 9374928879
Thanks
75
Shyam N. Chawda 9374928879

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Java script arrays
Java script arraysJava script arrays
Java script arrays
 
JSP
JSPJSP
JSP
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
 
Html 5 New Features
Html 5 New FeaturesHtml 5 New Features
Html 5 New Features
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Java script
Java scriptJava script
Java script
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Asp objects
Asp objectsAsp objects
Asp objects
 

Destacado (20)

Validation controls ppt
Validation controls pptValidation controls ppt
Validation controls ppt
 
Seminar ppt on digital signature
Seminar ppt on digital signatureSeminar ppt on digital signature
Seminar ppt on digital signature
 
Presentation on asp.net controls
Presentation on asp.net controlsPresentation on asp.net controls
Presentation on asp.net controls
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
Ch3 server controls
Ch3 server controlsCh3 server controls
Ch3 server controls
 
Asp.Net Control Architecture
Asp.Net Control ArchitectureAsp.Net Control Architecture
Asp.Net Control Architecture
 
State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
 
Electronic data interchange
Electronic data interchangeElectronic data interchange
Electronic data interchange
 
Edi ppt
Edi pptEdi ppt
Edi ppt
 
How to make more impact as an engineer
How to make more impact as an engineerHow to make more impact as an engineer
How to make more impact as an engineer
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Electronic data interchange
Electronic data interchangeElectronic data interchange
Electronic data interchange
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net Ajax
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web Forms
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Presentation - Electronic Data Interchange
Presentation - Electronic Data InterchangePresentation - Electronic Data Interchange
Presentation - Electronic Data Interchange
 
Standard control in asp.net
Standard control in asp.netStandard control in asp.net
Standard control in asp.net
 

Similar a State Management in ASP.NET

State management 1
State management 1State management 1
State management 1singhadarsh
 
State management
State managementState management
State managementIblesoft
 
State management
State managementState management
State managementLalit Kale
 
State management
State managementState management
State managementIblesoft
 
High performance coding practices code project
High performance coding practices code projectHigh performance coding practices code project
High performance coding practices code projectPruthvi B Patil
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerKumar Gupta
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerKumar Gupta
 
Master page and Theme ASP.NET with VB.NET
Master page and Theme ASP.NET with VB.NETMaster page and Theme ASP.NET with VB.NET
Master page and Theme ASP.NET with VB.NETShyam Sir
 
Benchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers - A practical studyBenchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers - A practical studyKeerthi Balasundram
 
Benchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers -  A practical studyBenchmarking top IaaS providers -  A practical study
Benchmarking top IaaS providers - A practical studyKeerthi Balasundram
 
ppt_project_group_2.ppt amnd project report
ppt_project_group_2.ppt amnd project reportppt_project_group_2.ppt amnd project report
ppt_project_group_2.ppt amnd project reportsobanmoriwala1
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State ManagementRandy Connolly
 
QSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & AQSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & APalakMazumdar1
 
Data Layer - MeasureCamp VII 2015
Data Layer - MeasureCamp VII 2015Data Layer - MeasureCamp VII 2015
Data Layer - MeasureCamp VII 2015Simo Ahava
 
ASP.NET with VB.NET
 ASP.NET with VB.NET ASP.NET with VB.NET
ASP.NET with VB.NETShyam Sir
 
Up and Running with Angular
Up and Running with AngularUp and Running with Angular
Up and Running with AngularJustin James
 
8\9 SSIS 2008R2_Training - Debugging_Package
8\9 SSIS 2008R2_Training - Debugging_Package8\9 SSIS 2008R2_Training - Debugging_Package
8\9 SSIS 2008R2_Training - Debugging_PackagePramod Singla
 

Similar a State Management in ASP.NET (20)

State management 1
State management 1State management 1
State management 1
 
State management
State managementState management
State management
 
State management
State managementState management
State management
 
State management
State managementState management
State management
 
High performance coding practices code project
High performance coding practices code projectHigh performance coding practices code project
High performance coding practices code project
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunner
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunner
 
Master page and Theme ASP.NET with VB.NET
Master page and Theme ASP.NET with VB.NETMaster page and Theme ASP.NET with VB.NET
Master page and Theme ASP.NET with VB.NET
 
Benchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers - A practical studyBenchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers - A practical study
 
Benchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers -  A practical studyBenchmarking top IaaS providers -  A practical study
Benchmarking top IaaS providers - A practical study
 
ppt_project_group_2.ppt amnd project report
ppt_project_group_2.ppt amnd project reportppt_project_group_2.ppt amnd project report
ppt_project_group_2.ppt amnd project report
 
Hosting
HostingHosting
Hosting
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
QSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & AQSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & A
 
Data Layer - MeasureCamp VII 2015
Data Layer - MeasureCamp VII 2015Data Layer - MeasureCamp VII 2015
Data Layer - MeasureCamp VII 2015
 
ASP.NET with VB.NET
 ASP.NET with VB.NET ASP.NET with VB.NET
ASP.NET with VB.NET
 
Ch05 state management
Ch05 state managementCh05 state management
Ch05 state management
 
Up and Running with Angular
Up and Running with AngularUp and Running with Angular
Up and Running with Angular
 
Asp.net
Asp.netAsp.net
Asp.net
 
8\9 SSIS 2008R2_Training - Debugging_Package
8\9 SSIS 2008R2_Training - Debugging_Package8\9 SSIS 2008R2_Training - Debugging_Package
8\9 SSIS 2008R2_Training - Debugging_Package
 

Más de Shyam Sir

Mobile Application
Mobile ApplicationMobile Application
Mobile ApplicationShyam Sir
 
MVC First Basic
MVC First BasicMVC First Basic
MVC First BasicShyam Sir
 
Basic Concept of ASP.NET
Basic Concept of ASP.NETBasic Concept of ASP.NET
Basic Concept of ASP.NETShyam Sir
 
If Else .. Select Case in VB.NET
If Else .. Select Case in VB.NETIf Else .. Select Case in VB.NET
If Else .. Select Case in VB.NETShyam Sir
 
Operators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETOperators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETShyam Sir
 

Más de Shyam Sir (6)

Mobile Application
Mobile ApplicationMobile Application
Mobile Application
 
It new2015
It new2015It new2015
It new2015
 
MVC First Basic
MVC First BasicMVC First Basic
MVC First Basic
 
Basic Concept of ASP.NET
Basic Concept of ASP.NETBasic Concept of ASP.NET
Basic Concept of ASP.NET
 
If Else .. Select Case in VB.NET
If Else .. Select Case in VB.NETIf Else .. Select Case in VB.NET
If Else .. Select Case in VB.NET
 
Operators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NETOperators , Functions and Options in VB.NET
Operators , Functions and Options in VB.NET
 

State Management in ASP.NET

  • 2. Welcome my dear students2 Shyam N. Chawda 9374928879
  • 3. IsPostBack Property Page class’s property , which you can use to detect whether the page has already been post back to server. True/False True – Yes 2nd time For View Effects Take Dropdown and Add items in the form load Take Button 3 Shyam N. Chawda 9374928879
  • 4. What is State management? HTTP protocol is a stateless protocol. Web server does not have any idea about the requests from where they coming On each request web pages are created and destroyed. 4 Shyam N. Chawda 9374928879
  • 5. What is State management? A new instance of the Web page class is created each time the page is posted to the server. All information associated with the page and the controls on the page would be lost with each round trip. 5 Shyam N. Chawda 9374928879
  • 6. What is State management? So, how do we make web pages which will remember about the user ? 6 Shyam N. Chawda 9374928879
  • 7. What is State management? Client-Based Server-Based 7 Shyam N. Chawda 9374928879
  • 8. What is State management? Client-Based 8 Shyam N. Chawda 9374928879
  • 9. Shyam N. Chawda 93749288799 Client side View state Cookies Query strings Hidden fields
  • 10. What is State management? Server-Based 10 Shyam N. Chawda 9374928879
  • 11. Shyam N. Chawda 937492887911 Server side Application state Database Session state
  • 12. Client Side state management Query String For understand it you must aware about Request and Response object 12 Shyam N. Chawda 9374928879
  • 13. Response Object You can use this class to inject text into the page, jump to other page etc. Write Redirect 13 Shyam N. Chawda 9374928879
  • 14. Request Object Provides access to the current page request, including the request headers, cookies, query string, and so on. IsSecureConnection Checks to see whether you are communicating via an HTTPS secure protocol or not. 14 Shyam N. Chawda 9374928879
  • 16. Query string Information that is appended to the end of a page URL. You can use a query string to submit data back to your page or to another page through the URL. Query strings provide a simple but limited way to maintain state information. 16 Shyam N. Chawda 9374928879
  • 17. Query string For example in first page you collect information about your client, name and use this information in your second page. Take 2 forms Take 1 textbox and one button Response.Redirect("Page2.aspx?Name=" & TextBox1.Text Request.QueryString("Name") 17 Shyam N. Chawda 9374928879
  • 19. Query string Advantages No server resources are required Widespread support Almost all browsers and client devices support using query strings to pass values. Simple implementation 19 Shyam N. Chawda 9374928879
  • 20. Query string Disadvantages Potential security risks The information in the query string is directly visible to the user via the browser's user interface. Limited capacity Some browsers and client devices impose a 2083-character limit on the length of URLs. 20 Shyam N. Chawda 9374928879
  • 21. More than one Query string Using & Dim str As String str = "PageRequest.aspx?Name=" & TextBox1.Text & "&" & "Lname=" & TextBox2.Text 21 Shyam N. Chawda 9374928879
  • 22. View State View State is used to remember controls state when page is posted back to server. You can store page-specific information 22 Shyam N. Chawda 9374928879
  • 23. View State The view state is implemented with a hidden form field called _VIEWSTATE, which is automatically created in every Web page. When page is created on web sever this hidden control is populate with state of the controls and when page is posted back to server this information is retrieved and assigned to controls. 23 Shyam N. Chawda 9374928879
  • 24. View State 24 Shyam N. Chawda 9374928879
  • 25. View State Go View Source Each control on a Web Forms page has a ViewState property. Take example of DropdownList Set Property EnableViewState=True Take also one button 25 Shyam N. Chawda 9374928879
  • 26. View State <%@ Page Language="VB" EnableViewState="false" AutoEventWireup="false" CodeFile="frmViewState.aspx.vb" Inherits="frmViewState" %> By default true. So, even if it’s all the controls has set the property Enableviewstate=True but they are not working. 26 Shyam N. Chawda 9374928879
  • 27. View State Take 2 Buttons and 1 TextBox Take one variable before all the coding Assign that variable in one button click and display in the textbox Click and 2nd button and write the same logic. 27 Shyam N. Chawda 9374928879
  • 28. View State no = 5 ViewState("No") = no TextBox1.Text = ViewState ("No") 28 Shyam N. Chawda 9374928879
  • 29. Shyam N. Chawda 937492887929 So,Moral of the story about ViewState EnableViewState property for each control EnableviewState attribute of the @Page (Page directive) View source _ViewState Store value using ViewState(Key)
  • 30. View State Advantages No server resources are required Simple implementation View state does not require any custom programming to use. It is on by default to maintain state data on controls. 30 Shyam N. Chawda 9374928879
  • 31. View State Enhanced security features The values in view state are hashed, compressed, and encoded for Unicode implementations, which provides more security than using hidden fields. 31 Shyam N. Chawda 9374928879
  • 32. View State Disadvantages Performance considerations Storing large values can cause the page to slow down when users display it and when they post it. This is especially relevant for mobile devices, where bandwidth is often a limitation. 32 Shyam N. Chawda 9374928879
  • 33. View State Device limitations Mobile devices might not have the memory capacity to store a large amount of view-state data. 33 Shyam N. Chawda 9374928879
  • 34. Hidden Fields You can store page-specific information. This control is not visible when the application is viewed in the browser. Storage area for page specific. You must submit your pages to the server using the HTTP POST method 34 Shyam N. Chawda 9374928879
  • 35. Shyam N. Chawda 937492887935
  • 36. Hidden Fields Does not render in a Web browser. However, you can set the properties of the hidden field. A hidden field stores a single variable in its value property and must be explicitly added to the page. 36 Shyam N. Chawda 9374928879
  • 37. Hidden Fields Advantages No server resources are required Widespread support Almost all browsers and client devices support forms with hidden fields. 37 Shyam N. Chawda 9374928879
  • 38. Hidden Fields Simple implementation Hidden fields are standard HTML controls that require no complex programming logic. 38 Shyam N. Chawda 9374928879
  • 39. Hidden Fields Disadvantages Potential security risks The information in the hidden field can be seen if the page output source is viewed directly, creating a potential security issue. Encrypt and decrypt the contents of a hidden field, but doing so requires extra coding and overhead. 39 Shyam N. Chawda 9374928879
  • 40. Hidden Fields Performance considerations Because hidden fields are stored in the page itself, storing large values can cause the page to slow Storage limitations If the amount of data in a hidden field becomes very large, some proxies and firewalls will prevent access to the page that contains them. 40 Shyam N. Chawda 9374928879
  • 41. Cookies A Cookie is a small text file that the browser creates and stores on the hard drive of your machine. Cookie is just one or more pieces of information stored as text strings. 41 Shyam N. Chawda 9374928879
  • 42. Cookies Cookies are useful for storing small amounts of frequently changed information on the client. The cookie contains information the Web application can read whenever the user visits the site. Cookies are associated with a Web site, not with a specific page, so the browser and server will exchange cookie information. 42 Shyam N. Chawda 9374928879
  • 43. Cookies Good example 1. A site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. 2. Ebay assigns you an ID 43 Shyam N. Chawda 9374928879
  • 44. Cookies Good example 1. A site conducting a poll might use a cookie simply as a Boolean value to indicate whether a user's browser has already participated in voting so that the user cannot vote twice. 2. Ebay assigns you an ID 44 Shyam N. Chawda 9374928879
  • 45. Cookies Cookies can either be temporary or persistent. When creating a cookie, you specify a Name and Value. Each cookie must have a unique name. You can also set a cookie's date and time expiration. 45 Shyam N. Chawda 9374928879
  • 46. Cookies If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. 46 Shyam N. Chawda 9374928879
  • 47. Sets - Cookies Dim aCookie As New HttpCookie("lastVisit") aCookie.Values("Name") = txtName.Text aCookie.Values("Dt") = DateTime.Now.ToString aCookie.Expires = DateTime.Now.AddDays(1) Response.Cookies.Add(aCookie) 47 Shyam N. Chawda 9374928879
  • 48. Gets - Cookies If Not Request.Cookies("lastVisit") Is Nothing Then txtNameR.Text = Request.Cookies("lastVisit").Values("Name").ToStri ng txtDateR.Text = Request.Cookies("lastVisit").Values("Dt").ToString End if 48 Shyam N. Chawda 9374928879
  • 49. Cookies Advantages No server resources are required Simplicity The cookie is a lightweight, text-based structure. 49 Shyam N. Chawda 9374928879
  • 50. Cookies Advantages Data persistence Although the durability of the cookie on a client computer is subject to cookie expiration processes on the client and user intervention, cookies are generally the most durable form of data persistence on the client. 50 Shyam N. Chawda 9374928879
  • 51. Cookies Disadvantages Size limitations Most browsers place a 4096-byte limit on the size of a cookie, although support for 8192-byte 51 Shyam N. Chawda 9374928879
  • 52. Cookies User-configured refusal Some users disable their browser or client device's ability to receive cookies, thereby limiting this functionality. 52 Shyam N. Chawda 9374928879
  • 53. Cookies Potential security risks Users can manipulate cookies on their computer, which can potentially cause a security risk or cause the application that is dependent on the cookie to fail. 53 Shyam N. Chawda 9374928879
  • 54. What is State Management? Server-Based Application state Session state Database 54 Shyam N. Chawda 9374928879
  • 55. Application State Storing application wide-specific information such as objects and variables. All information stored in the application state is shared among all the pages of the Web application by using the HttpApplicationState class. 55 Shyam N. Chawda 9374928879
  • 56. Application State The ideal data to insert into application state variables is data that is shared by multiple sessions and does not change often. 56 Shyam N. Chawda 9374928879
  • 57. Application State Goto Global.asax Find Counter : Session_Start Application(“Cnt”)= Application(“Cnt”)= +1 57 Shyam N. Chawda 9374928879
  • 58. Application State Application("Message") = "Welcome to the LJ” Application("Cnt") = 0 Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Application("Cnt") = Application("Cnt") + 1 58 Shyam N. Chawda 9374928879
  • 59. Application State Advantages Simple implementation Application state is easy to use 59 Shyam N. Chawda 9374928879
  • 60. Application State Application scope Because application state is accessible to all pages in an application, storing information in application state can mean keeping only a single copy of the information 60 Shyam N. Chawda 9374928879
  • 61. Application State Disadvantages Limited durability of data Because global data that is stored in application state is volatile, it will be lost if the Web server process containing it is destroyed, such as from a server crash, upgrade, or shutdown. 61 Shyam N. Chawda 9374928879
  • 62. Application State Resource requirements Application state requires server memory, which can affect the performance of the server as well as the scalability of the application. 62 Shyam N. Chawda 9374928879
  • 63. Session State Use when you are storing short-lived information that is specific to an individual session and security is an issue. Do not store large quantities of information in session state. 63 Shyam N. Chawda 9374928879
  • 64. Session State Session("FirstName") = FirstNameTextBox.Text Session("LastName") = LastNameTextBox.Text Each active ASP.NET session is identified and tracked using a 120-bit.$ SessionID values are generated using an algorithm 64 Shyam N. Chawda 9374928879
  • 65. Session State The scope of session state is limited to the current browser session. If different users are accessing a Web application, each will have a different session state. Create Login Form 65 Shyam N. Chawda 9374928879
  • 66. Session State The scope of session state is limited to the current browser session. If different users are accessing a Web application, each will have a different session state. Create Login Form 66 Shyam N. Chawda 9374928879
  • 67. Session State Advantages Simple implementation Data persistence Data placed in session-state variables can be preserved through Internet Information Services (IIS) restarts and worker-process restarts without losing session data because the data is stored in another process space. 67 Shyam N. Chawda 9374928879
  • 68. Session State Cookieless support Session state works with browsers that do not support HTTP cookies, although session state is most commonly used with cookies to provide user identification facilities to a Web application. 68 Shyam N. Chawda 9374928879
  • 69. Session State Cookieless support Session state works with browsers that do not support HTTP cookies, although session state is most commonly used with cookies to provide user identification facilities to a Web application. 69 Shyam N. Chawda 9374928879
  • 70. Session State Disadvantage Performance considerations Session-state variables stay in memory until they are either removed or replaced. 70 Shyam N. Chawda 9374928879
  • 71. Database Database enables you to store large amount of information pertaining to state in your Web application. Sometimes users continually query the database by using the unique ID, you can save it in the database for use across multiple request for the pages in your site. 71 Shyam N. Chawda 9374928879
  • 72. Database Advantages Security Access to databases requires rigorous authentication and authorization. 72 Shyam N. Chawda 9374928879
  • 73. Database Storage capacity You can store as much information as you like in a database. Data persistence Database information can be stored as long as you like, and it is not subject to the availability of the Web server. 73 Shyam N. Chawda 9374928879
  • 74. Database Disadvantage Complexity Using a database to support state management requires that the hardware and software configurations be more complex. 74 Shyam N. Chawda 9374928879