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
- client side state management
- Server side state management
Explain client side state management
- 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.
- 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.
- control state : It persist the information about control, if view state is disable still control state will work.
- 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.
- 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.
- HttpCookie cookie = new HttpCookie(name);
- public void SetPersistentCookies(string name, string value){
- cookie.Value = value;
- cookie.Expires = Convert.ToDateTime(“12/12/2008”);
- Response.Cookies.Add(cookie);}
- 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.
- public void SetNonPersistentCookies(string name, string value){
- HttpCookie cookie = new HttpCookie(name);
- cookie.Value = value;
- Response.Cookies.Add(cookie);}
- 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
- session object
- 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()
{}
}