ASP.NET 12 - State Management

Randy Connolly
Randy ConnollyProfessor à Mount Royal University
Chapter 12 Managing ASP.NET State Everything is in a state …  Marcus Aurelius,  Meditations ,  ix. 19
Overview ,[object Object],[object Object],[object Object],[object Object]
Why is state necessary? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASP.NET State Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
View State ,[object Object],[object Object],ViewState["RequestCount"] = count; int count = (int)ViewState["RequestCount"];
View State ,[object Object],[object Object],[object Object],[object Object]
Serialization ,[object Object],[object Object],[object Object],[Serializable] public class Category  { private int _num; private string _name; private Market _market; ...  [Serializable] public class Market { ...
Uses of View State ,[object Object],[object Object],[object Object],[object Object],[object Object]
Misuses of View State ,[object Object],[object Object],[object Object],[object Object]
Query Strings ,[object Object],[object Object],[object Object],[object Object],http://www.whatever.com/file.aspx?page=resum%E9&name=John+Locke
Query Strings ,[object Object],[object Object],[object Object],[object Object]
Query Strings ,[object Object],[object Object],string url = "productPage.aspx?id=" + id; Response.Redirect(url); int id = Convert.ToInt32(Request["id“]); // use this id to construct SQL ... productPage.aspx
Cookies ,[object Object],[object Object],[object Object]
Cookies
Cookies ,[object Object],[object Object]
Cookies ,[object Object],[object Object]
Cookies HttpCookie cookie = new HttpCookie("Name",txtName.Text);   // Set expiry date to 1 day, 12 hours from now cookie.Expires = DateTime.Now + new TimeSpan(1, 12, 0, 0); Response.Cookies.Add(cookie); HttpCookie cookie = Request.Cookies["name"]; labCookie.Text = cookie.Value;
Application State ,[object Object],[object Object],[object Object],Application["SiteRequestCount"] = 0; HttpContext.Current.Application["SiteName"] = "www.site.com"; … int count = (int)Application["SiteRequestCount"]; string name = (string)Application["SiteName"];
Application State ,[object Object]
Application State ,[object Object],[object Object],[object Object],[object Object],[object Object],if (Application["SiteRequestCount"] == null) { Application["SiteRequestCount"] = 0;  // lazy initialization }   int count = (int)Application["SiteRequestCount"]; count++; Application["SiteRequestCount"] = count; Application.Lock(); if (Application["SiteRequestCount"] == null) { Application["SiteRequestCount"] = 0;  // lazy initialization }   int count = (int)Application["SiteRequestCount"]; count++; Application["SiteRequestCount"] = count; Application.Unlock();
Application State ,[object Object],[object Object],<%@ Application Language=&quot;C#&quot; %>   <script runat=&quot;server&quot;>   void Application_Start(object sender, EventArgs e)  { // Code that runs on application startup Application[&quot;SiteRequestCount&quot;] = 0; Application[&quot;SiteName&quot;] = &quot;www.somesite.com&quot;; } …  </script>
Session State ,[object Object],[object Object],[object Object],[object Object],[object Object]
Session State ,[object Object],[object Object],[object Object]
Session State ,[object Object],[object Object],if (Session[&quot;Cart&quot;] == null) { Session[&quot;Cart&quot;] = new ShoppingCart(); } ShoppingCart cart = (ShoppingCart)Session[&quot;Cart&quot;];
How Does Session State Work? ,[object Object],[object Object],[object Object],http://…/Ch11/(S(hlxh3ibe2htriazpxdne3b55))/Sample.aspx
How Does Session State Work? ,[object Object],[object Object],[object Object],[object Object]
How Does Session State Work?
State Providers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
In-Process Session Provider ,[object Object],[object Object],[object Object],[object Object]
Other Session Providers ,[object Object],[object Object],[object Object],[object Object]
Other Session Providers ,[object Object],[object Object]
State Server Session Provider ,[object Object],[object Object]
SQL Server Session Provider ,[object Object],[object Object],[object Object]
SQL Server Session Provider
ASP.NET Cache ,[object Object],[object Object],[object Object]
Cache ,[object Object],[object Object]
Cache ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],<%@ OutputCache Duration=&quot;60&quot; VaryByParam=&quot;None&quot; %> BookCatalogLogic bcl = new BookCatalogLogic(); publishers = bcl.GetAllPublishers();   Cache[&quot;PublisherKey&quot;] = publishers;
1 sur 37

Recommandé

ASP.NET 02 - How ASP.NET Works par
ASP.NET 02 - How ASP.NET WorksASP.NET 02 - How ASP.NET Works
ASP.NET 02 - How ASP.NET WorksRandy Connolly
15.8K vues34 diapositives
Web II - 02 - How ASP.NET Works par
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksRandy Connolly
10.4K vues98 diapositives
Csphtp1 20 par
Csphtp1 20Csphtp1 20
Csphtp1 20HUST
12.6K vues126 diapositives
AJAX par
AJAXAJAX
AJAXGouthaman V
561 vues27 diapositives
Asp.net. par
Asp.net.Asp.net.
Asp.net.Naveen Sihag
31.2K vues84 diapositives
Ajax par
AjaxAjax
Ajaxhusnara mohammad
275 vues34 diapositives

Contenu connexe

Tendances

Using MongoDB with the .Net Framework par
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkStefano Paluello
5.5K vues24 diapositives
ASP.NET 03 - Working With Web Server Controls par
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsRandy Connolly
3.1K vues43 diapositives
AJAX par
AJAXAJAX
AJAXARJUN
656 vues16 diapositives
Jquery Ajax par
Jquery AjaxJquery Ajax
Jquery AjaxAnand Kumar Rajana
1.6K vues4 diapositives
JSP Error handling par
JSP Error handlingJSP Error handling
JSP Error handlingkamal kotecha
7.6K vues22 diapositives
Data Access Mobile Devices par
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devicesvenkat987
940 vues30 diapositives

Tendances(19)

En vedette

Entity Framework Overview par
Entity Framework OverviewEntity Framework Overview
Entity Framework Overviewukdpe
2.7K vues23 diapositives
CSS Basics par
CSS BasicsCSS Basics
CSS BasicsHossein Zahed
1.4K vues10 diapositives
Big Data World par
Big Data WorldBig Data World
Big Data WorldHossein Zahed
6.8K vues80 diapositives
ASP.NET MVC 5 - EF 6 - VS2015 par
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
3.4K vues148 diapositives
HTML & XHTML Basics par
HTML & XHTML BasicsHTML & XHTML Basics
HTML & XHTML BasicsHossein Zahed
3.1K vues37 diapositives
CSharp Language Overview Part 1 par
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1Hossein Zahed
1.8K vues126 diapositives

En vedette(13)

Entity Framework Overview par ukdpe
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
ukdpe2.7K vues
ASP.NET MVC 5 - EF 6 - VS2015 par Hossein Zahed
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed3.4K vues
CSharp Language Overview Part 1 par Hossein Zahed
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
Hossein Zahed1.8K vues
Developing an ASP.NET Web Application par Rishi Kothari
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
Rishi Kothari28.4K vues
ASP.NET MVC Interview Questions and Answers by Shailendra Chauhan par Shailendra Chauhan
ASP.NET MVC Interview Questions and Answers by Shailendra ChauhanASP.NET MVC Interview Questions and Answers by Shailendra Chauhan
ASP.NET MVC Interview Questions and Answers by Shailendra Chauhan
Shailendra Chauhan245.5K vues
Introduction to angular js for .net developers par Mohd Manzoor Ahmed
Introduction to angular js  for .net developersIntroduction to angular js  for .net developers
Introduction to angular js for .net developers
Mohd Manzoor Ahmed2.1K vues

Similaire à ASP.NET 12 - State Management

State management par
State managementState management
State managementIblesoft
1.1K vues5 diapositives
State management par
State managementState management
State managementLalit Kale
1.3K vues21 diapositives
Chapter 8 part1 par
Chapter 8   part1Chapter 8   part1
Chapter 8 part1application developer
396 vues23 diapositives
State management par
State managementState management
State managementIblesoft
6.9K vues26 diapositives
Session and state management par
Session and state managementSession and state management
Session and state managementPaneliya Prince
174 vues89 diapositives
State management par
State managementState management
State managementMuhammad Amir
953 vues31 diapositives

Similaire à ASP.NET 12 - State Management(20)

State management par Iblesoft
State managementState management
State management
Iblesoft1.1K vues
State management par Lalit Kale
State managementState management
State management
Lalit Kale1.3K vues
State management par Iblesoft
State managementState management
State management
Iblesoft6.9K vues
IEEE KUET SPAC presentation par ahsanmm
IEEE KUET SPAC  presentationIEEE KUET SPAC  presentation
IEEE KUET SPAC presentation
ahsanmm360 vues
C sharp and asp.net interview questions par Akhil Mittal
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
Akhil Mittal1.2K vues
05 asp.net session07 par Vivek chan
05 asp.net session0705 asp.net session07
05 asp.net session07
Vivek chan126 vues
State management par teach4uin
State managementState management
State management
teach4uin2.3K vues
High performance coding practices code project par Pruthvi B Patil
High performance coding practices code projectHigh performance coding practices code project
High performance coding practices code project
Pruthvi B Patil498 vues
C# cookieless session id and application state par Malav Patel
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
Malav Patel399 vues
06 asp.net session08 par Vivek chan
06 asp.net session0806 asp.net session08
06 asp.net session08
Vivek chan324 vues

Plus de Randy Connolly

Ten-Year Anniversary of our CIS Degree par
Ten-Year Anniversary of our CIS DegreeTen-Year Anniversary of our CIS Degree
Ten-Year Anniversary of our CIS DegreeRandy Connolly
301 vues12 diapositives
Careers in Computing (2019 Edition) par
Careers in Computing (2019 Edition)Careers in Computing (2019 Edition)
Careers in Computing (2019 Edition)Randy Connolly
125 vues35 diapositives
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop... par
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...Randy Connolly
92 vues49 diapositives
Where is the Internet? (2019 Edition) par
Where is the Internet? (2019 Edition)Where is the Internet? (2019 Edition)
Where is the Internet? (2019 Edition)Randy Connolly
85 vues78 diapositives
Modern Web Development (2018) par
Modern Web Development (2018)Modern Web Development (2018)
Modern Web Development (2018)Randy Connolly
118 vues83 diapositives
Helping Prospective Students Understand the Computing Disciplines par
Helping Prospective Students Understand the Computing DisciplinesHelping Prospective Students Understand the Computing Disciplines
Helping Prospective Students Understand the Computing DisciplinesRandy Connolly
157 vues56 diapositives

Plus de Randy Connolly(20)

Ten-Year Anniversary of our CIS Degree par Randy Connolly
Ten-Year Anniversary of our CIS DegreeTen-Year Anniversary of our CIS Degree
Ten-Year Anniversary of our CIS Degree
Randy Connolly301 vues
Careers in Computing (2019 Edition) par Randy Connolly
Careers in Computing (2019 Edition)Careers in Computing (2019 Edition)
Careers in Computing (2019 Edition)
Randy Connolly125 vues
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop... par Randy Connolly
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Randy Connolly92 vues
Where is the Internet? (2019 Edition) par Randy Connolly
Where is the Internet? (2019 Edition)Where is the Internet? (2019 Edition)
Where is the Internet? (2019 Edition)
Randy Connolly85 vues
Helping Prospective Students Understand the Computing Disciplines par Randy Connolly
Helping Prospective Students Understand the Computing DisciplinesHelping Prospective Students Understand the Computing Disciplines
Helping Prospective Students Understand the Computing Disciplines
Randy Connolly157 vues
Constructing a Web Development Textbook par Randy Connolly
Constructing a Web Development TextbookConstructing a Web Development Textbook
Constructing a Web Development Textbook
Randy Connolly91 vues
Disrupting the Discourse of the "Digital Disruption of _____" par Randy Connolly
Disrupting the Discourse of the "Digital Disruption of _____"Disrupting the Discourse of the "Digital Disruption of _____"
Disrupting the Discourse of the "Digital Disruption of _____"
Randy Connolly77 vues
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip... par Randy Connolly
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Randy Connolly54 vues
Constructing and revising a web development textbook par Randy Connolly
Constructing and revising a web development textbookConstructing and revising a web development textbook
Constructing and revising a web development textbook
Randy Connolly828 vues
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines par Randy Connolly
Computing is Not a Rock Band: Student Understanding of the Computing DisciplinesComputing is Not a Rock Band: Student Understanding of the Computing Disciplines
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
Randy Connolly920 vues
Citizenship: How do leaders in universities think about and experience citize... par Randy Connolly
Citizenship: How do leaders in universities think about and experience citize...Citizenship: How do leaders in universities think about and experience citize...
Citizenship: How do leaders in universities think about and experience citize...
Randy Connolly583 vues
A longitudinal examination of SIGITE conference submission data par Randy Connolly
A longitudinal examination of SIGITE conference submission dataA longitudinal examination of SIGITE conference submission data
A longitudinal examination of SIGITE conference submission data
Randy Connolly873 vues
Is Human Flourishing in the ICT World of the Future Likely? par Randy Connolly
Is Human Flourishing in the ICT World of the Future Likely?Is Human Flourishing in the ICT World of the Future Likely?
Is Human Flourishing in the ICT World of the Future Likely?
Randy Connolly3.4K vues
Constructing a Contemporary Textbook par Randy Connolly
Constructing a Contemporary TextbookConstructing a Contemporary Textbook
Constructing a Contemporary Textbook
Randy Connolly659 vues

Dernier

MVP and prioritization.pdf par
MVP and prioritization.pdfMVP and prioritization.pdf
MVP and prioritization.pdfrahuldharwal141
40 vues8 diapositives
Measuring User on the web with the core web vitals - by @theafolayan.pptx par
Measuring User on the web with the core web vitals - by @theafolayan.pptxMeasuring User on the web with the core web vitals - by @theafolayan.pptx
Measuring User on the web with the core web vitals - by @theafolayan.pptxOluwaseun Raphael Afolayan
14 vues13 diapositives
Inawisdom IDP par
Inawisdom IDPInawisdom IDP
Inawisdom IDPPhilipBasford
17 vues48 diapositives
Deep Tech and the Amplified Organisation: Core Concepts par
Deep Tech and the Amplified Organisation: Core ConceptsDeep Tech and the Amplified Organisation: Core Concepts
Deep Tech and the Amplified Organisation: Core ConceptsHolonomics
17 vues21 diapositives
Telenity Solutions Brief par
Telenity Solutions BriefTelenity Solutions Brief
Telenity Solutions BriefMustafa Kuğu
14 vues10 diapositives
CryptoBotsAI par
CryptoBotsAICryptoBotsAI
CryptoBotsAIchandureddyvadala199
42 vues5 diapositives

Dernier(20)

Deep Tech and the Amplified Organisation: Core Concepts par Holonomics
Deep Tech and the Amplified Organisation: Core ConceptsDeep Tech and the Amplified Organisation: Core Concepts
Deep Tech and the Amplified Organisation: Core Concepts
Holonomics17 vues
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... par ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue209 vues
Optimizing Communication to Optimize Human Behavior - LCBM par Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar39 vues
Discover Aura Workshop (12.5.23).pdf par Neo4j
Discover Aura Workshop (12.5.23).pdfDiscover Aura Workshop (12.5.23).pdf
Discover Aura Workshop (12.5.23).pdf
Neo4j20 vues
This talk was not generated with ChatGPT: how AI is changing science par Elena Simperl
This talk was not generated with ChatGPT: how AI is changing scienceThis talk was not generated with ChatGPT: how AI is changing science
This talk was not generated with ChatGPT: how AI is changing science
Elena Simperl34 vues
"Node.js Development in 2024: trends and tools", Nikita Galkin par Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays37 vues
Digital Personal Data Protection (DPDP) Practical Approach For CISOs par Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash171 vues
The Coming AI Tsunami.pptx par johnhandby
The Coming AI Tsunami.pptxThe Coming AI Tsunami.pptx
The Coming AI Tsunami.pptx
johnhandby14 vues
Business Analyst Series 2023 - Week 4 Session 8 par DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray10180 vues
The Power of Generative AI in Accelerating No Code Adoption.pdf par Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf

ASP.NET 12 - State Management

  • 1. Chapter 12 Managing ASP.NET State Everything is in a state … Marcus Aurelius, Meditations , ix. 19
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 15.
  • 16.
  • 17. Cookies HttpCookie cookie = new HttpCookie(&quot;Name&quot;,txtName.Text);   // Set expiry date to 1 day, 12 hours from now cookie.Expires = DateTime.Now + new TimeSpan(1, 12, 0, 0); Response.Cookies.Add(cookie); HttpCookie cookie = Request.Cookies[&quot;name&quot;]; labCookie.Text = cookie.Value;
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. How Does Session State Work?
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. SQL Server Session Provider
  • 35.
  • 36.
  • 37.