SlideShare a Scribd company logo
• The Problem of State
• View State
• The ViewState Collection
• Cross-Page Posting
• The Query String
• Cookies
• Session State
• Using Session Object to display
  Session Details
• Stateless HTTP connection.

• Additional steps required to retain information for
  a longer period of time or over the lifetime of the
  application.

• The information can be as simple as a user’s
  name or as complex as a stuffed full shopping
  cart for an ecommerce site.
View state uses a hidden field that ASP.NET automatically
inserts in the final, rendered HTML of a web page.

It’s a perfect place to store information that’s used for
multiple postbacks in a single web page.

The Web Server stores most of the properties of the Web
Controls of a requested page directly to its view state and
retrieve it later when the page is posted back.
• Every item in a View State is stored in a separate “slot”
  using a unique string name.

• ViewState["Counter"] = 1;

• ViewState collection stores all items as basic objects
  so you also need to cast the retrieved value to the
  appropriate data type using the casting syntax

• int counter;
• counter = (int)ViewState["Counter"];
ASP.NET runs the view state through a hashing
algorithm (with the help of a secret key value). The
hashing algorithm creates a hash code. Which is
added at the end of the view state data and sent to the
browser.

When the page is posted back, ASP.NET then checks
whether the checksum it calculated matches the hash
code. If a malicious user changes part of the view
state data, that doesn’t match.
If your view state contains some information you want
to keep secret, you can enable view state encryption.
You can turn on encryption for an individual page
using the ViewStateEncryptionMode property of
the Page directive:

<%@Page ViewStateEncryptionMode="Always" %>
Or

<configuration>
<system.web>
<pages viewStateEncryptionMode="Always" />
...
</system.web>
</configuration>
You can store your own objects in view state just as
easily as you store numeric and string types.

However, to store an item in view state, ASP.NET
must be able to convert it into a stream of bytes so
that it can be added to the hidden input field in the
page. This process is called serialization.

If your objects aren’t serializable (and by default
they’re not), you’ll receive an error message when
you attempt to place them in view state.

To make your objects serializable, you need to add a
Serializable attribute before your class declaration.
One of the most significant limitations with view state
is that it’s tightly bound to a specific page.

If the user navigates to another page, this information
is lost. Two basic techniques to transfer information
between pages are:

 Cross-page posting
 Query string
With Cross-Page Posting one page can send the user to
another page, complete with all the information for that
Page.

The infrastructure that supports cross-page postbacks is a
property named PostBackUrl which comes with
 ImageButton, LinkButton, and Button

To use cross-posting, you simply set PostBackUrl to the
name of another web form.

When the user clicks the button, the page will be posted to
that new URL with the values from all the input controls on
the current page.
Response.Redirect("newpage.aspx?recordID=10");

You can send multiple parameters as long as
they’re separated with an ampersand (&):

Response.Redirect("newpage.aspx?recordID=10&
mode=full");

The receiving can receive the values from
the QueryString dictionary collection exposed by
the built-in Request object:

string ID = Request.QueryString["recordID"];
• Information is limited to simple strings, which must
contain URL-legal characters.

• Information is clearly visible to the user and to anyone
else who cares to eavesdrop on the Internet.

• The enterprising user might decide to modify the query
string and supply new values, which your program won’t
expect and can’t protect against.

• Many browsers impose a limit on the length of a URL
(usually from 1KB to 2KB). For that reason, you can’t
place a large amount of information in the query string.
One potential problem with the query string is that some
characters aren’t allowed in a URL. Furthermore, some
characters have special meaning. For example, the
ampersand (&) is used to separate multiple query string
parameters, the plus sign (+) is an alternate way to represent
a space, and the number sign (#) is used to point to a
specific bookmark in a web page.

string url = "QueryStringRecipient.aspx?";
url += "Item=" + Server.UrlEncode (lstItems. SelectedItem.Text) + "&";
url += "Mode=" + chkDetails.Checked.ToString();
Response.Redirect(url);
Cookies are small files that are created in the web
browser’s memory (if they’re temporary) or on the
client’s hard drive (if they’re permanent).

They work transparently without the user being aware
that information needs to be stored.

They also can be easily used by any page in your
application and even be retained between visits,
which allows for truly long-term storage.
•   They’re limited to simple string information

•   They’re easily accessible and readable if the user
    finds and opens the corresponding file.

•   Some users disable cookies on their browsers,
    which will cause problems for web applications
    that require them.

•   Users might manually delete the cookie files
    stored on their hard drives.
using System.Net;

// Create the cookie object.
HttpCookie cookie = new HttpCookie("Preferences");

// Set a value in it.
cookie["LanguagePref"] = "English";

// Add another value.
cookie["Country"] = "US";

// Add it to the current web response.
Response.Cookies.Add(cookie);

// This cookie lives for one year.
cookie.Expires = DateTime.Now.AddYears(1);
You retrieve cookies by cookie name using the
Request.Cookies collection:

HttpCookie cookie = Request.Cookies["Preferences"];
if (cookie != null)
{
language = cookie["LanguagePref"];
}
The only way to remove a cookie is by replacing it
with a cookie that has an expiration date that has
already passed.

HttpCookie cookie = new HttpCookie("Preferences");
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie);
An application might need to store and access complex
information such as custom data objects, which can’t
be sent through a query string.

Or the application might have stringent security
requirements that prevent it from storing information
about a client in view state or in a custom cookie.

Session state management allows you to store any
type of data in memory on the server. Every client that
accesses the application is given a distinct session ID.
ASP.NET tracks each session using a unique 120-bit
identifier.

ASP.NET uses a proprietary algorithm to generate this value,
thereby guaranteeing (statistically speaking) that the number
is unique and it’s random enough that a malicious user can’t
reverse-engineer or “guess” what session ID a given client
will be using.

This ID is the only piece of session-related information that is
transmitted between the web server and the client.

When the client presents the session ID, ASP.NET looks up
the corresponding session, retrieves the objects you stored
previously, and places them into a special collection so they
can be accessed in your code.
Using cookies: In this case, the session ID is transmitted in
a special cookie (named ASP.NET_SessionId), which
ASP.NET creates automatically when the session collection
is used. This is the default.

Using modified URLs: In this case, the session ID is
transmitted in a specially modified (or munged) URL.
This allows you to create applications that use session
state with clients that don’t support cookies.
• If the user closes and restarts the browser.

• If the user accesses the same page through a
  different browser window, although the session
  will still exist if a web page is accessed through
  the original browser window. Browsers differ on
  how they handle this situation.

• If the session times out due to inactivity.

• If your web page code ends the session by
  calling the Session.Abandon() method.
You can interact with session state using the

System.Web.SessionState.HttpSessionState

class which is provided in an ASP.NET web
page as the built-in Session object.
Chapter 8   part1
lblSession.Text = "Session ID: " + Session.SessionID;
lblSession.Text += "<br />Number of Objects: ";
lblSession.Text += Session.Count.ToString();
lblSession.Text += "<br />Mode: " + Session.Mode.ToString();
lblSession.Text += "<br />Is Cookieless: ";
lblSession.Text += Session.IsCookieless.ToString();
lblSession.Text += "<br />Is New: ";
lblSession.Text += Session.IsNewSession.ToString();
lblSession.Text += "<br />Timeout (minutes): ";
lblSession.Text += Session.Timeout.ToString();
Ad

More Related Content

What's hot (14)

State management in ASP .NET
State  management in ASP .NETState  management in ASP .NET
State management in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
 
ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
Julie Iskander
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
Vivek Singh Chandel
 
Search engine optimization (seo) from Endeca & ATG
Search engine optimization (seo) from Endeca & ATGSearch engine optimization (seo) from Endeca & ATG
Search engine optimization (seo) from Endeca & ATG
Vignesh sitaraman
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
Randy Connolly
 
MICROSOFT ASP.NET ONLINE TRAINING
MICROSOFT ASP.NET ONLINE TRAININGMICROSOFT ASP.NET ONLINE TRAINING
MICROSOFT ASP.NET ONLINE TRAINING
Santhosh Sap
 
State management 1
State management 1State management 1
State management 1
singhadarsh
 
Lecture8
Lecture8Lecture8
Lecture8
Châu Thanh Chương
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's Guide
Keyur Shah
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
Vivek Singh Chandel
 
State management
State managementState management
State management
Muhammad Amir
 
Managing states
Managing statesManaging states
Managing states
Paneliya Prince
 
Programming web application
Programming web applicationProgramming web application
Programming web application
aspnet123
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
Lior Zamir
 

Similar to Chapter 8 part1 (20)

19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
Julie Iskander
 
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
 
State Management.pptx
State Management.pptxState Management.pptx
State Management.pptx
DrMonikaPatel2
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
Jayaprasanna4
 
Ecom2
Ecom2Ecom2
Ecom2
Santosh Pandey
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
 
C# cookieless session id and application state
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
Malav Patel
 
Advance Java
Advance JavaAdvance Java
Advance Java
Maitree Patel
 
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
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
Mazenetsolution
 
81.pptx ajx fyjc semester paper 2 parrtens
81.pptx ajx fyjc semester paper 2 parrtens81.pptx ajx fyjc semester paper 2 parrtens
81.pptx ajx fyjc semester paper 2 parrtens
epfoportal69
 
state managment
state managment state managment
state managment
aniliimd
 
Caching in Kentico 11
Caching in Kentico 11Caching in Kentico 11
Caching in Kentico 11
Christopher Bass
 
Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
sandeep54552
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
application developer
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
aspnet123
 
Session 32 - Session Management using Cookies
Session 32 - Session Management using CookiesSession 32 - Session Management using Cookies
Session 32 - Session Management using Cookies
PawanMM
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
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
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
Jayaprasanna4
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
 
C# cookieless session id and application state
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
Malav Patel
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
Mazenetsolution
 
81.pptx ajx fyjc semester paper 2 parrtens
81.pptx ajx fyjc semester paper 2 parrtens81.pptx ajx fyjc semester paper 2 parrtens
81.pptx ajx fyjc semester paper 2 parrtens
epfoportal69
 
state managment
state managment state managment
state managment
aniliimd
 
Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
sandeep54552
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
aspnet123
 
Session 32 - Session Management using Cookies
Session 32 - Session Management using CookiesSession 32 - Session Management using Cookies
Session 32 - Session Management using Cookies
PawanMM
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
Ad

More from application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
application developer
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
application developer
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
application developer
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
application developer
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
application developer
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
application developer
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
application developer
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
application developer
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
application developer
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
application developer
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
application developer
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
application developer
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
application developer
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
application developer
 
C # test paper
C # test paperC # test paper
C # test paper
application developer
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
application developer
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
application developer
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
application developer
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
application developer
 
Ad

Recently uploaded (20)

Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 

Chapter 8 part1

  • 1. • The Problem of State • View State • The ViewState Collection • Cross-Page Posting • The Query String • Cookies • Session State • Using Session Object to display Session Details
  • 2. • Stateless HTTP connection. • Additional steps required to retain information for a longer period of time or over the lifetime of the application. • The information can be as simple as a user’s name or as complex as a stuffed full shopping cart for an ecommerce site.
  • 3. View state uses a hidden field that ASP.NET automatically inserts in the final, rendered HTML of a web page. It’s a perfect place to store information that’s used for multiple postbacks in a single web page. The Web Server stores most of the properties of the Web Controls of a requested page directly to its view state and retrieve it later when the page is posted back.
  • 4. • Every item in a View State is stored in a separate “slot” using a unique string name. • ViewState["Counter"] = 1; • ViewState collection stores all items as basic objects so you also need to cast the retrieved value to the appropriate data type using the casting syntax • int counter; • counter = (int)ViewState["Counter"];
  • 5. ASP.NET runs the view state through a hashing algorithm (with the help of a secret key value). The hashing algorithm creates a hash code. Which is added at the end of the view state data and sent to the browser. When the page is posted back, ASP.NET then checks whether the checksum it calculated matches the hash code. If a malicious user changes part of the view state data, that doesn’t match.
  • 6. If your view state contains some information you want to keep secret, you can enable view state encryption. You can turn on encryption for an individual page using the ViewStateEncryptionMode property of the Page directive: <%@Page ViewStateEncryptionMode="Always" %> Or <configuration> <system.web> <pages viewStateEncryptionMode="Always" /> ... </system.web> </configuration>
  • 7. You can store your own objects in view state just as easily as you store numeric and string types. However, to store an item in view state, ASP.NET must be able to convert it into a stream of bytes so that it can be added to the hidden input field in the page. This process is called serialization. If your objects aren’t serializable (and by default they’re not), you’ll receive an error message when you attempt to place them in view state. To make your objects serializable, you need to add a Serializable attribute before your class declaration.
  • 8. One of the most significant limitations with view state is that it’s tightly bound to a specific page. If the user navigates to another page, this information is lost. Two basic techniques to transfer information between pages are:  Cross-page posting  Query string
  • 9. With Cross-Page Posting one page can send the user to another page, complete with all the information for that Page. The infrastructure that supports cross-page postbacks is a property named PostBackUrl which comes with  ImageButton, LinkButton, and Button To use cross-posting, you simply set PostBackUrl to the name of another web form. When the user clicks the button, the page will be posted to that new URL with the values from all the input controls on the current page.
  • 10. Response.Redirect("newpage.aspx?recordID=10"); You can send multiple parameters as long as they’re separated with an ampersand (&): Response.Redirect("newpage.aspx?recordID=10& mode=full"); The receiving can receive the values from the QueryString dictionary collection exposed by the built-in Request object: string ID = Request.QueryString["recordID"];
  • 11. • Information is limited to simple strings, which must contain URL-legal characters. • Information is clearly visible to the user and to anyone else who cares to eavesdrop on the Internet. • The enterprising user might decide to modify the query string and supply new values, which your program won’t expect and can’t protect against. • Many browsers impose a limit on the length of a URL (usually from 1KB to 2KB). For that reason, you can’t place a large amount of information in the query string.
  • 12. One potential problem with the query string is that some characters aren’t allowed in a URL. Furthermore, some characters have special meaning. For example, the ampersand (&) is used to separate multiple query string parameters, the plus sign (+) is an alternate way to represent a space, and the number sign (#) is used to point to a specific bookmark in a web page. string url = "QueryStringRecipient.aspx?"; url += "Item=" + Server.UrlEncode (lstItems. SelectedItem.Text) + "&"; url += "Mode=" + chkDetails.Checked.ToString(); Response.Redirect(url);
  • 13. Cookies are small files that are created in the web browser’s memory (if they’re temporary) or on the client’s hard drive (if they’re permanent). They work transparently without the user being aware that information needs to be stored. They also can be easily used by any page in your application and even be retained between visits, which allows for truly long-term storage.
  • 14. They’re limited to simple string information • They’re easily accessible and readable if the user finds and opens the corresponding file. • Some users disable cookies on their browsers, which will cause problems for web applications that require them. • Users might manually delete the cookie files stored on their hard drives.
  • 15. using System.Net; // Create the cookie object. HttpCookie cookie = new HttpCookie("Preferences"); // Set a value in it. cookie["LanguagePref"] = "English"; // Add another value. cookie["Country"] = "US"; // Add it to the current web response. Response.Cookies.Add(cookie); // This cookie lives for one year. cookie.Expires = DateTime.Now.AddYears(1);
  • 16. You retrieve cookies by cookie name using the Request.Cookies collection: HttpCookie cookie = Request.Cookies["Preferences"]; if (cookie != null) { language = cookie["LanguagePref"]; } The only way to remove a cookie is by replacing it with a cookie that has an expiration date that has already passed. HttpCookie cookie = new HttpCookie("Preferences"); cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cookie);
  • 17. An application might need to store and access complex information such as custom data objects, which can’t be sent through a query string. Or the application might have stringent security requirements that prevent it from storing information about a client in view state or in a custom cookie. Session state management allows you to store any type of data in memory on the server. Every client that accesses the application is given a distinct session ID.
  • 18. ASP.NET tracks each session using a unique 120-bit identifier. ASP.NET uses a proprietary algorithm to generate this value, thereby guaranteeing (statistically speaking) that the number is unique and it’s random enough that a malicious user can’t reverse-engineer or “guess” what session ID a given client will be using. This ID is the only piece of session-related information that is transmitted between the web server and the client. When the client presents the session ID, ASP.NET looks up the corresponding session, retrieves the objects you stored previously, and places them into a special collection so they can be accessed in your code.
  • 19. Using cookies: In this case, the session ID is transmitted in a special cookie (named ASP.NET_SessionId), which ASP.NET creates automatically when the session collection is used. This is the default. Using modified URLs: In this case, the session ID is transmitted in a specially modified (or munged) URL. This allows you to create applications that use session state with clients that don’t support cookies.
  • 20. • If the user closes and restarts the browser. • If the user accesses the same page through a different browser window, although the session will still exist if a web page is accessed through the original browser window. Browsers differ on how they handle this situation. • If the session times out due to inactivity. • If your web page code ends the session by calling the Session.Abandon() method.
  • 21. You can interact with session state using the System.Web.SessionState.HttpSessionState class which is provided in an ASP.NET web page as the built-in Session object.
  • 23. lblSession.Text = "Session ID: " + Session.SessionID; lblSession.Text += "<br />Number of Objects: "; lblSession.Text += Session.Count.ToString(); lblSession.Text += "<br />Mode: " + Session.Mode.ToString(); lblSession.Text += "<br />Is Cookieless: "; lblSession.Text += Session.IsCookieless.ToString(); lblSession.Text += "<br />Is New: "; lblSession.Text += Session.IsNewSession.ToString(); lblSession.Text += "<br />Timeout (minutes): "; lblSession.Text += Session.Timeout.ToString();