SlideShare une entreprise Scribd logo
1  sur  24
Module  14: Managing State
Overview ,[object Object],[object Object],[object Object]
Lesson: State Management ,[object Object],[object Object],[object Object],[object Object],[object Object]
What is State Management? First Name Last Name Please enter your logon information: John Submit Chen Web Server Login.aspx Login.aspx Web Server Hello  John Chen Greetings.aspx Please enter your logon information: John Submit Chen Hello  Greetings.aspx I forget who you are!! First Name Last Name Without State Management With State Management
Types of State Management ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Client-Side State Management Server-Side State Management
Server-Side State Management ,[object Object],[object Object],[object Object],[object Object],[object Object],Web Server Client Computer Application and Session variables SessionID
Client-Side State Management ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Web Server Client Computer Cookies
The Global.asax File ,[object Object],[object Object],[object Object],[object Object]
The Global.asax File ( continued ) ASP.NET Web Server Client ASP.NET HTTP Runtime IIS Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_ResolveRequestCache Application_AquireRequestState Application_PreRequestHandlerExecute Application_EndRequest Application_UpdateRequestCache Application_ReleaseRequestState Application_PostRequestHandlerExecute Page execution Request Response
Lesson: Application and Session Variables ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Initializing Application and Session Variables ,[object Object],[object Object],[object Object],Sub Application_Start(s As Object,e As EventArgs)  Application("NumberofVisitors") = 0 End Sub  protected void Application_Start(Object sender,EventArgs e) {  Application["NumberofVisitors"] = 0; }
Using Application and Session Variables ,[object Object],[object Object],Session("BackColor") = "blue" Application.Lock() Application("NumberOfVisitors") += 1 Application.UnLock()   strBgColor = Session("BackColor") lblNbVisitor.Text = Application("NumberOfVisitors") Session["BackColor"] = "blue"; Application.Lock(); Application["NumberOfVisitors"] =    (int)Application["NumberOfVisitors"]  + 1; Application.UnLock(); strBgColor = (string)Session["BackColor"]; lblNbVisitor.Text = Application["NumberOfVisitors"].ToString();
Demonstration: Using Session Variables ,[object Object],[object Object],[object Object],[object Object]
Application and Session Variable Duration ,[object Object],[object Object],[object Object],[object Object],<configuration> <system.web> <sessionState timeout=&quot;10&quot; /> </system.web> </configuration>
Scalable Storage of Application and Session Variables ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],SQL Session and Application variables Client Web farm Session and Application variables -Or- State server
Saving Application and Session Variables in a Database ,[object Object],[object Object],[object Object],[object Object],<sessionState mode=&quot;SQLServer&quot; sqlConnectionString=&quot;data source= SQLServerName ; Integrated security=true&quot; /> c:gt; OSQL –S  SQLServerName  –E <InstallSqlState.sql 1 2
Lesson: Cookies and Cookieless Sessions ,[object Object],[object Object],[object Object],[object Object],[object Object]
Using Cookies to Store Session Data ,[object Object],[object Object],HttpCookie objCookie = new HttpCookie(&quot;myCookie&quot;); DateTime now = DateTime.Now; objCookie.Values.Add(&quot;Time&quot;, now.ToString()); objCookie.Values.Add(&quot;ForeColor&quot;, &quot;White&quot;); objCookie.Values.Add(&quot;BackColor&quot;, &quot;Blue&quot;); Response.Cookies.Add(objCookie); HttpCookie objCookie = new HttpCookie(&quot;myCookie&quot;); DateTime now = DateTime.Now; objCookie.Values.Add(&quot;Time&quot;, now.ToString()); objCookie.Values.Add(&quot;ForeColor&quot;, &quot;White&quot;); objCookie.Values.Add(&quot;BackColor&quot;, &quot;Blue&quot;); objCookie.Expires = now.AddHours(1); Response.Cookies.Add(objCookie); To create a persistent cookie, specify the expiration time Set-Cookie: Username=John+Chen; path=/;  domain=microsoft.com; Expires=Tuesday, 01-Feb-05 00.00.01 GMT
Instructor-Led Practice: Using Variables and Cookies ,[object Object],[object Object],[object Object]
Retrieving Information from a Cookie ,[object Object],[object Object],lblTime.Text = objCookie.Values(&quot;Time&quot;) lblTime.ForeColor = System.Drawing.Color.FromName _ (objCookie.Values(&quot;ForeColor&quot;)) lblTime.BackColor = System.Drawing.Color.FromName _ (objCookie.Values(&quot;BackColor&quot;)) Dim objCookie As HttpCookie = Request.Cookies(&quot;myCookie&quot;) HttpCookie objCookie = Request.Cookies[&quot;myCookie&quot;]; lblTime.Text = objCookie.Values[&quot;Time&quot;]; lblTime.ForeColor = System.Drawing.Color.FromName (objCookie.Values[&quot;ForeColor&quot;]); lblTime.BackColor = System.Drawing.Color.FromName (objCookie.Values[&quot;BackColor&quot;]);
Using Cookieless Sessions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://server/(h44a1e55c0breu552yrecobl)/page.aspx
Setting Up Cookieless Sessions ,[object Object],[object Object],<sessionState cookieless=&quot;true&quot; />
Review ,[object Object],[object Object],[object Object]
Lab  15:  Storing Application and Session Data Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx  Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web  Service dentalService1.asmx  Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu  Component Class1.vb or Class1.cs XML Files Web. config

Contenu connexe

Similaire à 2310 b 14

State management
State managementState management
State managementIblesoft
 
State management
State managementState management
State managementteach4uin
 
StateManagement in ASP.Net.ppt
StateManagement in ASP.Net.pptStateManagement in ASP.Net.ppt
StateManagement in ASP.Net.pptcharusharma165
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07Vivek chan
 
Session and state management
Session and state managementSession and state management
Session and state managementPaneliya Prince
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State ManagementRandy Connolly
 
Session viii(state mngtserver)
Session viii(state mngtserver)Session viii(state mngtserver)
Session viii(state mngtserver)Shrijan Tiwari
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETPeter Gfader
 
State management in asp
State management in aspState management in asp
State management in aspIbrahim MH
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
Active server pages
Active server pagesActive server pages
Active server pagesmcatahir947
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Robert MacLean
 

Similaire à 2310 b 14 (20)

2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
State management
State managementState management
State management
 
State management
State managementState management
State management
 
StateManagement in ASP.Net.ppt
StateManagement in ASP.Net.pptStateManagement in ASP.Net.ppt
StateManagement in ASP.Net.ppt
 
05 asp.net session07
05 asp.net session0705 asp.net session07
05 asp.net session07
 
State management
State managementState management
State management
 
Session and state management
Session and state managementSession and state management
Session and state management
 
ASP.NET 12 - State Management
ASP.NET 12 - State ManagementASP.NET 12 - State Management
ASP.NET 12 - State Management
 
Session viii(state mngtserver)
Session viii(state mngtserver)Session viii(state mngtserver)
Session viii(state mngtserver)
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
Aspnet Caching
Aspnet CachingAspnet Caching
Aspnet Caching
 
Asp.net
Asp.netAsp.net
Asp.net
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
State management in asp
State management in aspState management in asp
State management in asp
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Active server pages
Active server pagesActive server pages
Active server pages
 
Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?Windows Server AppFabric Caching - What it is & when you should use it?
Windows Server AppFabric Caching - What it is & when you should use it?
 
Managing states
Managing statesManaging states
Managing states
 
Migration from ASP to ASP.NET
Migration from ASP to ASP.NETMigration from ASP to ASP.NET
Migration from ASP to ASP.NET
 

Plus de Krazy Koder (20)

2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xc
2310 b xc2310 b xc
2310 b xc
 
2310 b xb
2310 b xb2310 b xb
2310 b xb
 
2310 b 17
2310 b 172310 b 17
2310 b 17
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 13
2310 b 132310 b 13
2310 b 13
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
2310 b 10
2310 b 102310 b 10
2310 b 10
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 07
2310 b 072310 b 07
2310 b 07
 
2310 b 06
2310 b 062310 b 06
2310 b 06
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
2310 b 04
2310 b 042310 b 04
2310 b 04
 

2310 b 14

  • 1. Module 14: Managing State
  • 2.
  • 3.
  • 4. What is State Management? First Name Last Name Please enter your logon information: John Submit Chen Web Server Login.aspx Login.aspx Web Server Hello John Chen Greetings.aspx Please enter your logon information: John Submit Chen Hello Greetings.aspx I forget who you are!! First Name Last Name Without State Management With State Management
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. The Global.asax File ( continued ) ASP.NET Web Server Client ASP.NET HTTP Runtime IIS Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_ResolveRequestCache Application_AquireRequestState Application_PreRequestHandlerExecute Application_EndRequest Application_UpdateRequestCache Application_ReleaseRequestState Application_PostRequestHandlerExecute Page execution Request Response
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. Lab 15: Storing Application and Session Data Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web Service dentalService1.asmx Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu Component Class1.vb or Class1.cs XML Files Web. config