SlideShare a Scribd company logo
State
Management
Dr. Monika Patel
State Overview
• Browsers are generally stateless.
• Stateless means, whenever we visit a website, our browser communicates
with the respective server depending on our requested functionality or
the request.
• The browser communicates with the respective server using the HTTP or
HTTPs protocol.
• But after that response, what's next or what will happen when we visit
that website again after closing our web browser?
• In this case HTTP/HTTPs doesn't remember what website or URL we
visited.
• In other words we can say it doesn't hold the state of a previous website
that we visited before closing our browser, that is called stateless.
State Management
• State management is very important and useful in ASP.NET.
• ASP.NET State management is a preserve state control and object in an
application because ASP.NET web applications are stateless.
• A new instance of the Web page class is created each time the page is
posted to the server.
• If a user enters information into a web application, that information
would be lost in the round trip from the browser (MSDN).
• State management maintains and stores the information of any user till
the end of the user session.
Types of State Management
State Management
Client- Side
Management
ViewState QueryString Cookies
Server-Side
Managanement
Application State Session State
Client-Side State Management
•Whenever we use Client-Side State
Management, the state related
information will directly get stored on the
client-side.
•That specific information will travel back
and communicate with every request
generated by the user then afterwards
provides responses after server-side
communication.
Continue…
Server-Side State Management
•In Server-Side State Management all the
information is stored in the user
memory.
•Due to this functionality there is more
secure domains at the server side in
comparison to Client-Side State
Management.
Continue…
Client-side Techniques
•Client-Side State Management techniques
are,
a) View State
b) Hidden field
c) Cookies
d) Control State
e) Query Strings
ViewState
•ViewState is a important client side state
management technique.
•View State is the method to preserve the Value of
the Page and Controls between round trips.
•Preserving the value of page controls between
client to server and server to client is
called "roundtrip".
•It stores the page or control value in the mode of
hidden fields.
Continue…
• The ViewState is a dictionary kind of object which stores the
value on the basis of KEY/VALUE.
• By default, the ViewState is enabled, but we can enable or
disable ViewState on Page level or Control level.
There are two properties on Page Level
1) ViewStateMode
2) EnableVIewState
3) ViewStateEncryptionMode = “Always” / “Auto” / “Never”
• There is one property on Control Level.
• EnableViewState = “True” / “False”
Continue…
• Each web page and the controls on the page have the
EnableViewState property.
• User can set ViewState on/off for each control using EnableViewState
property.
• ASP.NET framework uses the ViewState property to automatically
save the values of the Web page and each control on the Web page
prior to rendering the page.
• User can also disable ViewState for the entire page by adding
EnableViewState= false to @page directive.
Enable/Disable Viewstate
• <%@ Page Language="C#" AutoEventWireup="true"
CodeFile=“WebStud.aspx.cs" EnableViewState="true"
Inherits="WebApplication1.Student" %>
How to store the value in ViewState?
• ViewState stores the value in a Key/Value pair basis.
Syntax
ViewState[“KeyName”] = Object / String .etc.
Data Types Can Store In Viewstate
• Integers
• String
• Boolean
• Array/ArrayList
• Hash Table
Features Of View State
1) Retains the value of the Control after post-back without using a
session.
2) Stores the value of Pages and Control Properties defined in the
page.
3) Creates a custom View State Provider that lets you store View
State Information in a SQL Server Database or in another data
store.
Advantages of View State
1) Easy to Implement.
2) No server resources are required: The View State is contained in a
structure within the page load.
3) Enhanced security features: It can be encoded and compressed or
Unicode implementation.
Disadvantages of View State
1) Security Risk: The Information of View State can be seen in the page
output source directly. You can manually encrypt and decrypt the
contents of a Hidden Field, but It requires extra coding. If security is a
concern then consider using a Server-Based state Mechanism so that
no sensitive information is sent to the client.
2) Performance: Performance is not good if we use a large amount of
data because View State is stored in the page itself and storing a
large value can cause the page to be slow.
3) Device limitation: Mobile Devices might not have the memory
capacity to store a large amount of View State data.
4) It can store values for the same page only.
When We Should Use View State
• When the data to be stored is small.
• Try to avoid secure data.
Querystring
• A query string is one of the techniques in Web applications to
send data from one webform to another through the URL.
• A query string consists of two parts, field and value, and each
of pair separated by ampersand (&).
• The ?(question mark) in a query string indicates the beginning
of a query string and it's value.
• There is a limit on the Query string length.
• Hence, Query strings cannot be used to send very long data.
• Some browsers and client devices impose a 2083 character
limit on the length of the URL.
• Most browsers impose a limit of 255 characters on URL length.
• Query strings are visible to the user, hence should not be used
to send sensitive information such as a username and password
but we can also encrypt query values.
Advantages
• Simple to Implement
• No server resources are required
• Widespread support
• Almost all browsers and client devices support using query strings to
pass values.
• Query strings contain the HTTP request for a specific URL.
Disadvantages
• Cross paging functionality makes it redundant
• Easily modified by end user
• Potential security risks due to Human Readable: 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.
Sending Only One Querystring Value
• Sender Page:
Response.Redirect(“PageName+Keyname=Value”);
• Receiver Page:
Str = Request.QueryString[“Keyname”];
Sending More Than One Querystring Value
• Sender Page:
Response.Redirect(“PageName+Keyname1=Value1&KeyName2=
Value2”);
• Receiver Page:
Str1 = Request.QueryString[“Keyname1”];
Str2 = Request.QueryString[“Keyname2”];
Cookies
• A cookie is a small amount of data that is stored either in a text file on the
client file system or in-memory in the client browser session.
• This file is located on client machines "C:Document and
SettingsCurrently_Login userCookie" path.
• It is used to store user preference information like Username,
Password,City and PhoneNo etc on client machines.
• We need to import namespace called Systen.Web.HttpCookie before we
use cookie.
Continue…
• Usually a cookie can have a maximum size of 4KB.
• A particular named cookie can store a single value or a collection of
name/value pairs.
• Each cookie must have a unique name.
• User can set a cookie’s date and time expiration.
• If user does not set the cookie’s expiration, the cookie is created but
it is not stored on the user’s hard disk.
Types of Cookies
There are two types of cookies:
1.Persistence Cookie
2.Non-Persistence Cookie
1. Persistence Cookie
Cookies which have an expiry date time are called
persistence cookies.
This types of cookies are stored on user’s hard
drive permanently till the date time we set.
Continue…
2. Non-Persistence Cookie
• This types of cookies are not permanently stored on user hard drive.
• It stores the information up the user accessing the same browser.
• When user close the browser the cookies will be automatically
deleted.
Continue…
• Store Value:
HttpCookie Cookiename = new HttpCookie(“Storecookiename”);
Cookiename.Values[“Keyname”] = Value;
Cookiename.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(Cookiename);
• Fetch Value:
Variable name = Request.Cookies[“Storecookiename”].Values["KeyName"].ToString();
Advantages
• Its clear text so user can able to read it.
• We can store user preference information on the client machine.
• Its easy way to maintain.
• Fast accessing.
Disadvantages
• Size limitations
• Most browsers place a 4096-byte limit on the size of a cookie,
although support for 8192-byte
• Most browsers allow only 20 cookies per site; if you try to store
more, the oldest cookies are discarded.
• Cookies can be disabled on user browsers
• Cookies are transmitted for each HTTP request/response causing
overhead on bandwidth.
• Inappropriate for sensitive data due to security is not provided.

More Related Content

Similar to State Management.pptx

Session and Cookies.pdf
Session and Cookies.pdfSession and Cookies.pdf
Session and Cookies.pdf
HamnaGhani1
 
state managment
state managment state managment
state managment aniliimd
 
ASP.NET View State - Security Issues
ASP.NET View State - Security IssuesASP.NET View State - Security Issues
ASP.NET View State - Security Issues
Ronan Dunne, CEH, SSCP
 
state management asp.net
 state management asp.net state management asp.net
state management asp.net
Pratiksha Srivastava
 
State management 1
State management 1State management 1
State management 1singhadarsh
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
Julie Iskander
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
Sam Bowne
 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status Codes
DeeptiJava
 
Session and state management
Session and state managementSession and state management
Session and state management
Paneliya Prince
 
Asp.net
Asp.netAsp.net
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
Nuha Noor
 
Lecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptxLecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptx
Balkrishanpatidar
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
sandeep54552
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuery
SIVAKUMAR V
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
Shivanand Arur
 
Security asp.net application
Security asp.net applicationSecurity asp.net application
Security asp.net application
ZAIYAUL HAQUE
 
Ch 13: Attacking Users: Other Techniques (Part 2)
Ch 13: Attacking Users: Other Techniques (Part 2)Ch 13: Attacking Users: Other Techniques (Part 2)
Ch 13: Attacking Users: Other Techniques (Part 2)
Sam Bowne
 

Similar to State Management.pptx (20)

Session and cookies,get and post
Session and cookies,get and postSession and cookies,get and post
Session and cookies,get and post
 
Session and Cookies.pdf
Session and Cookies.pdfSession and Cookies.pdf
Session and Cookies.pdf
 
state managment
state managment state managment
state managment
 
ASP.NET View State - Security Issues
ASP.NET View State - Security IssuesASP.NET View State - Security Issues
ASP.NET View State - Security Issues
 
state management asp.net
 state management asp.net state management asp.net
state management asp.net
 
State management 1
State management 1State management 1
State management 1
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
 
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
 
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status Codes
 
Session and state management
Session and state managementSession and state management
Session and state management
 
Asp.net
Asp.netAsp.net
Asp.net
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
 
Lecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptxLecture32-Web-based-testing-II.pptx
Lecture32-Web-based-testing-II.pptx
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuery
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
Security asp.net application
Security asp.net applicationSecurity asp.net application
Security asp.net application
 
Ch 13: Attacking Users: Other Techniques (Part 2)
Ch 13: Attacking Users: Other Techniques (Part 2)Ch 13: Attacking Users: Other Techniques (Part 2)
Ch 13: Attacking Users: Other Techniques (Part 2)
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 

State Management.pptx

  • 2. State Overview • Browsers are generally stateless. • Stateless means, whenever we visit a website, our browser communicates with the respective server depending on our requested functionality or the request. • The browser communicates with the respective server using the HTTP or HTTPs protocol. • But after that response, what's next or what will happen when we visit that website again after closing our web browser? • In this case HTTP/HTTPs doesn't remember what website or URL we visited. • In other words we can say it doesn't hold the state of a previous website that we visited before closing our browser, that is called stateless.
  • 3. State Management • State management is very important and useful in ASP.NET. • ASP.NET State management is a preserve state control and object in an application because ASP.NET web applications are stateless. • A new instance of the Web page class is created each time the page is posted to the server. • If a user enters information into a web application, that information would be lost in the round trip from the browser (MSDN). • State management maintains and stores the information of any user till the end of the user session.
  • 4. Types of State Management State Management Client- Side Management ViewState QueryString Cookies Server-Side Managanement Application State Session State
  • 5. Client-Side State Management •Whenever we use Client-Side State Management, the state related information will directly get stored on the client-side. •That specific information will travel back and communicate with every request generated by the user then afterwards provides responses after server-side communication.
  • 7. Server-Side State Management •In Server-Side State Management all the information is stored in the user memory. •Due to this functionality there is more secure domains at the server side in comparison to Client-Side State Management.
  • 9. Client-side Techniques •Client-Side State Management techniques are, a) View State b) Hidden field c) Cookies d) Control State e) Query Strings
  • 10. ViewState •ViewState is a important client side state management technique. •View State is the method to preserve the Value of the Page and Controls between round trips. •Preserving the value of page controls between client to server and server to client is called "roundtrip". •It stores the page or control value in the mode of hidden fields.
  • 11. Continue… • The ViewState is a dictionary kind of object which stores the value on the basis of KEY/VALUE. • By default, the ViewState is enabled, but we can enable or disable ViewState on Page level or Control level. There are two properties on Page Level 1) ViewStateMode 2) EnableVIewState 3) ViewStateEncryptionMode = “Always” / “Auto” / “Never” • There is one property on Control Level. • EnableViewState = “True” / “False”
  • 12. Continue… • Each web page and the controls on the page have the EnableViewState property. • User can set ViewState on/off for each control using EnableViewState property. • ASP.NET framework uses the ViewState property to automatically save the values of the Web page and each control on the Web page prior to rendering the page. • User can also disable ViewState for the entire page by adding EnableViewState= false to @page directive.
  • 13. Enable/Disable Viewstate • <%@ Page Language="C#" AutoEventWireup="true" CodeFile=“WebStud.aspx.cs" EnableViewState="true" Inherits="WebApplication1.Student" %>
  • 14. How to store the value in ViewState? • ViewState stores the value in a Key/Value pair basis. Syntax ViewState[“KeyName”] = Object / String .etc.
  • 15. Data Types Can Store In Viewstate • Integers • String • Boolean • Array/ArrayList • Hash Table
  • 16. Features Of View State 1) Retains the value of the Control after post-back without using a session. 2) Stores the value of Pages and Control Properties defined in the page. 3) Creates a custom View State Provider that lets you store View State Information in a SQL Server Database or in another data store.
  • 17. Advantages of View State 1) Easy to Implement. 2) No server resources are required: The View State is contained in a structure within the page load. 3) Enhanced security features: It can be encoded and compressed or Unicode implementation.
  • 18. Disadvantages of View State 1) Security Risk: The Information of View State can be seen in the page output source directly. You can manually encrypt and decrypt the contents of a Hidden Field, but It requires extra coding. If security is a concern then consider using a Server-Based state Mechanism so that no sensitive information is sent to the client. 2) Performance: Performance is not good if we use a large amount of data because View State is stored in the page itself and storing a large value can cause the page to be slow. 3) Device limitation: Mobile Devices might not have the memory capacity to store a large amount of View State data. 4) It can store values for the same page only.
  • 19. When We Should Use View State • When the data to be stored is small. • Try to avoid secure data.
  • 20. Querystring • A query string is one of the techniques in Web applications to send data from one webform to another through the URL. • A query string consists of two parts, field and value, and each of pair separated by ampersand (&). • The ?(question mark) in a query string indicates the beginning of a query string and it's value. • There is a limit on the Query string length. • Hence, Query strings cannot be used to send very long data. • Some browsers and client devices impose a 2083 character limit on the length of the URL. • Most browsers impose a limit of 255 characters on URL length. • Query strings are visible to the user, hence should not be used to send sensitive information such as a username and password but we can also encrypt query values.
  • 21. Advantages • Simple to Implement • No server resources are required • Widespread support • Almost all browsers and client devices support using query strings to pass values. • Query strings contain the HTTP request for a specific URL.
  • 22. Disadvantages • Cross paging functionality makes it redundant • Easily modified by end user • Potential security risks due to Human Readable: 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.
  • 23. Sending Only One Querystring Value • Sender Page: Response.Redirect(“PageName+Keyname=Value”); • Receiver Page: Str = Request.QueryString[“Keyname”];
  • 24. Sending More Than One Querystring Value • Sender Page: Response.Redirect(“PageName+Keyname1=Value1&KeyName2= Value2”); • Receiver Page: Str1 = Request.QueryString[“Keyname1”]; Str2 = Request.QueryString[“Keyname2”];
  • 25. Cookies • A cookie is a small amount of data that is stored either in a text file on the client file system or in-memory in the client browser session. • This file is located on client machines "C:Document and SettingsCurrently_Login userCookie" path. • It is used to store user preference information like Username, Password,City and PhoneNo etc on client machines. • We need to import namespace called Systen.Web.HttpCookie before we use cookie.
  • 26. Continue… • Usually a cookie can have a maximum size of 4KB. • A particular named cookie can store a single value or a collection of name/value pairs. • Each cookie must have a unique name. • User can set a cookie’s date and time expiration. • If user does not set the cookie’s expiration, the cookie is created but it is not stored on the user’s hard disk.
  • 27. Types of Cookies There are two types of cookies: 1.Persistence Cookie 2.Non-Persistence Cookie 1. Persistence Cookie Cookies which have an expiry date time are called persistence cookies. This types of cookies are stored on user’s hard drive permanently till the date time we set.
  • 28. Continue… 2. Non-Persistence Cookie • This types of cookies are not permanently stored on user hard drive. • It stores the information up the user accessing the same browser. • When user close the browser the cookies will be automatically deleted.
  • 29. Continue… • Store Value: HttpCookie Cookiename = new HttpCookie(“Storecookiename”); Cookiename.Values[“Keyname”] = Value; Cookiename.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(Cookiename); • Fetch Value: Variable name = Request.Cookies[“Storecookiename”].Values["KeyName"].ToString();
  • 30. Advantages • Its clear text so user can able to read it. • We can store user preference information on the client machine. • Its easy way to maintain. • Fast accessing.
  • 31. Disadvantages • Size limitations • Most browsers place a 4096-byte limit on the size of a cookie, although support for 8192-byte • Most browsers allow only 20 cookies per site; if you try to store more, the oldest cookies are discarded. • Cookies can be disabled on user browsers • Cookies are transmitted for each HTTP request/response causing overhead on bandwidth. • Inappropriate for sensitive data due to security is not provided.