• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
State management
 

State management

on

  • 1,743 views

I am not the author of this file but wanted to collect it for study purpose.

I am not the author of this file but wanted to collect it for study purpose.

Statistics

Views

Total Views
1,743
Views on SlideShare
1,743
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    State management State management Presentation Transcript

    •  
    • ? Why State Management?
        • Web form pages are HTTP-Based, they are stateless, which means they don’t know whether the requests are all from the same client.
        • pages are destroyed and recreated with each round trip to the server.
        • information will be lost.
      Why State Management?
    • What is State Management?
    • What is State Management?
      • The state Management is a storage mechanism that is store user’s data across the moves between pages and postback of page. It’s accessible from One or all the web pages that were requested by a web browser.
      • The state Management is perfect for storing specific information that is connected to a specific user or Application Level.
      • Some state Management techniques has a timeout period and after the timeout the data is lost .The timeout occurs when the user is no longer active for a period of time.
    • Different Ways to Manage State?
      • Client-side state management .
      • Server-side state management.
    • Client-side State Management There is no information maintained on the server between round trips. Information will be stored in the page or on the client’s computer With Help Of ..
      • Query Strings.
      • Hidden Field.
      • Cookies.
      • View State .
      • Control State.
    • Server-side State Management
      • Applications object.
      • Session object.
      • Cache Object
      • Database.
      Information will be stored on the server, it has higher security but it can use more web server resources.
    • Client-side State Management Query Strings What are Query Strings? Query strings are data that is appended to the end of a page URL. They are commonly used to hold String data like page numbers or search terms or other data that isn't confidential. The user can see the values which the query string holds without using special operations. An example of a query string can look like http://www.Student.co.il?a=1;b=2. The Query String Structure As written earlier, query strings are appended to the end of a URL. First a question mark is appended to the URL's end and then every parameter that we want to hold in the query string . The parameters declare the parameter name followed by = symbol which followed by the data to hold. Every parameter is separated with the ampersand symbol(&).
      • Query String Limitations
          • You can use query string technique when passing Only String Type Data.
          • Risk When you pass non secure data.
          • Increase Network traffic.
          • There are a few browser limitation when using query strings that impose
        • a length limitation on the query string( 2083-character followed by Length Limit of URL ) .
      • Query String Advantage
          • Query strings provide a simple way to maintain state information.
          • Does not required server side resources.
      How To Use Query Strings When you need to use a query string data you do it in the following way:       string queryStringData = Request.QueryString["data"]; Query Strings Client-side State Management
    • Client-side State Management Hidden Field What are Hidden Fields ? A hidden field does not render visibly in the browser, but you can set its properties just as you can with a standard control. When a page is submitted to the server, the content of a hidden field is sent in the HTTP Form collection along with the values of other controls. A hidden field acts as a repository for any page-specific information that you would like to store directly in the page. Hidden field stores a single variable in its value property and must be explicitly added it to the page.ASP.NET provides the HtmlInputHidden control that offers hidden field functionality. Hidden Fields Values Hidden fields store only one value in their value property. The value is saved as a string and therefore in order to use it for other types you need to perform casting. You can see the stored data easily by using the View Source operation of the browser. You can see it by clicking the right mouse button and then choosing View Source from the menu (if the operation is available). The values has page context and therefore when you leave a page the data stored in the hidden fields is disposed.
      • Hidden Field Limitations
          • Hidden fields store only one value in their value property. The value is Only String Type Data and therefore in order to use it for other types you need to perform casting . 
          • Risk When you pass non secure data.
          • Increase Network traffic.
      • Hidden Field Advantage
          • Does not required server side resources so performance is high.
          • Can contain huge amount of data.
      How To Use Hidden Field protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1; //to assign a value to Hidden field Hidden1.Value=”this is a test”; //to retrieve a value string str=Hidden1.Value;
    • Cookies Client-side State Management What are Cookies? A cookie is a piece of data that is saved either in the memory of the client’s web browser or as a text file in the file system of the client. Cookies are used to identify a user, to store state information, preferences of the user and etc. How Does Cookies Mechanism Work? The mechanism of cookies is simple. When a client request a web page from a server the first request isn't containing a cookie . The server identify that the client has no cookie and generate . Then the server sends the cookie to the client and from now on the client will send the cookie in every request and the server will send the cookie in every response.
      • write the cookie to the response
        • Response.Cookies["cookie"].Value = "value“;
        • In the HttpCookie class there is a Expires property. If you don't use it (like in the example) the cookie is saved in memory and discarded if the user closes the browser. If you use the property you must define the amount of time the cookie is saved. In order to delete a saved cookie you need to use the Expires property and pass a past expiration date. There is no way to delete a cookie otherwise.
        • In the previous example the cookie saves a single value. The cookie can save multiple values like in the next example. Response.Cookies["cookie"]["key1"].Value = "value1";
        • Response.Cookies["cookie"]["key2"].Value = "value2";
        • Response.Cookies["cookie"]["key3"].Value = "value3";
      • How To Use Cookies?
        • Cookies are sent in the HTTP header of the response. To create a cookie you need to use the Response.Cookies property. To read a cookie value from the cookie use the Request.Cookies property.   The following example shows how to read a cookie named " cookie " and how to write the cookie :
        • // it can be different from null only is
        • // a request was made before
        • if (Request.Cookies["cookie"] != null)
        • {
        •    // get the cookie
        •    HttpCookie cookie = Request.Cookies["cookie"];
      •    // get the cookie value
      •    string value = Server.HtmlEncode(cookie.Value);
      • }
      •  
    • Cookies Limitations The clients can disable cookies . One way to check if cookies are disabled is to write a cookie to the Response and in the next Request to check if the cookie exists. If the cookie doesn't exists you need to assume that cookies are disabled.
      • Most browsers support cookies(Storage Limit) of up to 4096 bytes. This limitation makes the cookie s a way to store only small amount of data.
      • Browsers have a limit on the amount of cookies. A web site can save only 20 cookies .
      • The user can set the browser to disable cookies.
      • Less Secure.
      Cookies Advantage
      • Does not require server resources.
      • Store on Client's machine so performance is high.
        • Determine If a Browser Accepts Cookies
    • View State Client-side State Management What is View State? ViewSate is a technique to preserve controls data and maintain their properties during multiple requests for the same page how, the ViewState property provides a dictionary object for retaining values between multiple requests for the same page. When an ASP.NET page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden filed. How to use View State? You can use the ViewState property of the Control or Page class to add values to View State. The ViewState property exposes a dictionary of key and value pairs. For example, the following statement adds the string Hello World! to View State: ViewState(“message”) = “Hello World!”
    • View State Limitations
      • If this field gets too big, it can have a significant impact on your page’s performance.
      • Use Can read view state through page view source .
      View State Advantage
      • Does not require server resources.
      • Technically, User can add an instance of any serializable class to View State
    •  
    • Questions?
    • Further references Online http://www.oodesign.com http://www.programmersheaven.com http://www.dofactory.com Books