SlideShare uma empresa Scribd logo
1 de 37
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;

Mais conteúdo relacionado

Mais procurados

AJAX
AJAXAJAX
AJAX
ARJUN
 
Data Access Mobile Devices
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devices
venkat987
 
Programming web application
Programming web applicationProgramming web application
Programming web application
aspnet123
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 

Mais procurados (19)

Using MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net Framework
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
AJAX
AJAXAJAX
AJAX
 
Jquery Ajax
Jquery AjaxJquery Ajax
Jquery Ajax
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
Data Access Mobile Devices
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devices
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
Programming web application
Programming web applicationProgramming web application
Programming web application
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Ajax
AjaxAjax
Ajax
 
AJAX - An introduction
AJAX - An introductionAJAX - An introduction
AJAX - An introduction
 
Asp.net server control
Asp.net  server controlAsp.net  server control
Asp.net server control
 
HTML5 - An introduction
HTML5 - An introductionHTML5 - An introduction
HTML5 - An introduction
 
AJAX
AJAXAJAX
AJAX
 

Destaque

Microsoft SQL Server 2008
Microsoft SQL Server 2008Microsoft SQL Server 2008
Microsoft SQL Server 2008
Hossein Zahed
 

Destaque (13)

Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Big Data World
Big Data WorldBig Data World
Big Data World
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
HTML & XHTML Basics
HTML & XHTML BasicsHTML & XHTML Basics
HTML & XHTML Basics
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
 
SEO Fundamentals
SEO FundamentalsSEO Fundamentals
SEO Fundamentals
 
Microsoft SQL Server 2008
Microsoft SQL Server 2008Microsoft SQL Server 2008
Microsoft SQL Server 2008
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
MS.Net Interview Questions - Simplified
MS.Net Interview Questions - SimplifiedMS.Net Interview Questions - Simplified
MS.Net Interview Questions - Simplified
 
ASP.NET MVC Interview Questions and Answers by 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
 
Introduction to angular js for .net developers
Introduction to angular js  for .net developersIntroduction to angular js  for .net developers
Introduction to angular js for .net developers
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 

Semelhante a ASP.NET 12 - State Management

State management
State managementState management
State management
Iblesoft
 
State management
State managementState management
State management
Iblesoft
 
State management 1
State management 1State management 1
State management 1
singhadarsh
 
High performance coding practices code project
High performance coding practices code projectHigh performance coding practices code project
High performance coding practices code project
Pruthvi B Patil
 

Semelhante a ASP.NET 12 - State Management (20)

State management
State managementState management
State management
 
State management
State managementState management
State management
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 
State management
State managementState management
State management
 
Session and state management
Session and state managementSession and state management
Session and state management
 
State management
State managementState management
State management
 
Aspnet Caching
Aspnet CachingAspnet Caching
Aspnet Caching
 
Asp.net
Asp.netAsp.net
Asp.net
 
IEEE KUET SPAC presentation
IEEE KUET SPAC  presentationIEEE KUET SPAC  presentation
IEEE KUET SPAC presentation
 
State management 1
State management 1State management 1
State management 1
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
Ch05 state management
Ch05 state managementCh05 state management
Ch05 state management
 
PPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to serverPPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to server
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
Managing states
Managing statesManaging states
Managing states
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
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
 
2310 b 14
2310 b 142310 b 14
2310 b 14
 
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
 

Mais de 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...
Citizenship: How do leaders in universities think about and experience citize...
Randy Connolly
 

Mais de Randy Connolly (20)

Celebrating the Release of Computing Careers and Disciplines
Celebrating the Release of Computing Careers and DisciplinesCelebrating the Release of Computing Careers and Disciplines
Celebrating the Release of Computing Careers and Disciplines
 
Public Computing Intellectuals in the Age of AI Crisis
Public Computing Intellectuals in the Age of AI CrisisPublic Computing Intellectuals in the Age of AI Crisis
Public Computing Intellectuals in the Age of AI Crisis
 
Why Computing Belongs Within the Social Sciences
Why Computing Belongs Within the Social SciencesWhy Computing Belongs Within the Social Sciences
Why Computing Belongs Within the Social Sciences
 
Ten-Year Anniversary of our CIS Degree
Ten-Year Anniversary of our CIS DegreeTen-Year Anniversary of our CIS Degree
Ten-Year Anniversary of our CIS Degree
 
Careers in Computing (2019 Edition)
Careers in Computing (2019 Edition)Careers in Computing (2019 Edition)
Careers in Computing (2019 Edition)
 
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...
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
 
Where is the Internet? (2019 Edition)
Where is the Internet? (2019 Edition)Where is the Internet? (2019 Edition)
Where is the Internet? (2019 Edition)
 
Modern Web Development (2018)
Modern Web Development (2018)Modern Web Development (2018)
Modern Web Development (2018)
 
Helping Prospective Students Understand the Computing Disciplines
Helping Prospective Students Understand the Computing DisciplinesHelping Prospective Students Understand the Computing Disciplines
Helping Prospective Students Understand the Computing Disciplines
 
Constructing a Web Development Textbook
Constructing a Web Development TextbookConstructing a Web Development Textbook
Constructing a Web Development Textbook
 
Web Development for Managers
Web Development for ManagersWeb Development for Managers
Web Development for Managers
 
Disrupting the Discourse of the "Digital Disruption of _____"
Disrupting the Discourse of the "Digital Disruption of _____"Disrupting the Discourse of the "Digital Disruption of _____"
Disrupting the Discourse of the "Digital Disruption of _____"
 
17 Ways to Fail Your Courses
17 Ways to Fail Your Courses17 Ways to Fail Your Courses
17 Ways to Fail Your Courses
 
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...
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
 
Constructing and revising a web development textbook
Constructing and revising a web development textbookConstructing and revising a web development textbook
Constructing and revising a web development textbook
 
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
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
 
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...
Citizenship: How do leaders in universities think about and experience citize...
 
Thinking About Technology
Thinking About TechnologyThinking About Technology
Thinking About Technology
 
A longitudinal examination of SIGITE conference submission data
A longitudinal examination of SIGITE conference submission dataA longitudinal examination of SIGITE conference submission data
A longitudinal examination of SIGITE conference submission data
 
Web Security
Web SecurityWeb Security
Web Security
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

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.