Asp.net

Describe state management in Asp.net
State management is a technique that describe how to manage the state of object in asp.net.
Before describe state management i would like to define HTTP once because it will clear the all most of things.
As we know that http is a stateless protocol that can’t describe which request is coming from which user. It doesn’t identify whether 2 request is coming from same user or coming from different user. But real work scenario we always need to keep track of users.


So then we use state management mechanism.
there are 2 way to do it
  1. client side state  management
  2. Server side state management


Explain client side state management
  1. viewstate : Is use to track the value of control between the page request. And is work within the page only, not on next page. we can explicitly enable or disable viewstate property of a page or a control or an application.
  2. hidden : Is a html control which store data without displaying in control on browser, and we can get those data ( page-scoped data ) into server side by requesting the same page.
  1. control state : It persist the information about control, if view state is disable still control state will work.
  2. cookies : Is a small piece of information that server stores on the client’s browser. Whenever page request called server has tendency to read and write cookie information. There two type of cookies in ASP.NET.
    1. Persistent cookies:  cookies are stored on your computer hard disk.  They stay on your hard disk and can be accessed by web servers until they are deleted or have expired.
      1. HttpCookie cookie = new HttpCookie(name);
      2. public void SetPersistentCookies(string name, string value){
      3. cookie.Value = value;
      4. cookie.Expires = Convert.ToDateTime(“12/12/2008”);
      5. Response.Cookies.Add(cookie);}


    1. Non-persistent cookies: cookies are saved only while your web browser is running.  They can be used by a web server only until you close your browser.  They are not saved on your disk.
      1. public void SetNonPersistentCookies(string name, string value){
      2. HttpCookie cookie = new HttpCookie(name);
      3. cookie.Value = value;
      4. Response.Cookies.Add(cookie);}


  1. query string : Is a way to send data from one page to another page by page URL. It is not secured. We generally use ? and & identifier to send data across the page using query string.


server based management
    1. session object
    2. cache object


Session Management


  • InProc
    • Store on same server Worker Process
    • Cookie  browser


  • StateServer : On same or different server
  • SqlServer
  • Custom


What is partial class in c#?
Instead of defining multiple class we could define a single partial class which will act as same. At the compilation time all partial will be merged and treated as one.


Public partial class Employee
{
     public void DoWork()
     {}
}


Public partial class Employee
{
      public void GoToLunch()
      {}
}