Asp.net blogs

Sunday 7 July 2013

State Management

State Management : It is used to manage the state of stateless pages.

Types of State Management : There are two types of State Management are as shown below :

1. Client Side State Management.
2. Server Side State Management.

1. Client Side State Management : a) To use the Client resources means that information is stored on client hard-disk and client memory.

b) Secure : It is not secure means anyone can modify on client hard disk.

Types of Client Side State Management :

a. Cookies.
b. Query String.
c. View State.
d. Hidden State.
e Control State.

a) Cookies : Data stored in different types and this information stores and go to the next page, for this action we will used cookies.

=> To stored data in text file and that text file resides or store on client machine.
=> We can stores only string values but not object i.e Data Set not store.
=> Scope : Multiple pages means Make cookie in one page and access in any other pages.
=> By default Cookies are temporary and temporary cookies store on the browser memory.
                                    If we can off the browser then the cookie will destroy.
=> But we can also create Permanent Cookies and we can specify Expiry time for cookie. If System off then there is no effect on cookie.


b) Query String : It is also used for data storage.

=> Data concatenated with URL in query string.
=> Not stored in Text file.
=> We can store string value but didn't store objects.
=> Scope : Its scope is to the next page means one page to another page but cookie scope is more.
=> Maximum length of URL is  2086 characters.
=> Client side not secure means we can manipulate data in URL.


c) View State : Information is stored in view state in Hashed(#), Compressed, Encoded form.
                            Hash key generated for data retrieve and it is fast.

=> We can stores string value as well as objects like data set store.
=> We can store only serialisable object but we can't store Non-Serializable objects.
=> Scope :  To manage the state of current page.

For example : Information stored and goes to server and information retrieve when page comes from server.
 If we go to the next page and then come back to the previous page then Information is lost.

=> We can specify Encryption Mode for a View State like Always, Never , On Request.
=> We can specify  maximum page size for a view state. By default -1 means unlimited, but we can also apply limitation over there.

Drawbacks :

=> In large volume of data, Pagr slow and information or performance also slow down.


d) Hidden : Data display in URL but with the help of hidden we can hide the data.

=> We can also store string values but not objects.

=> Scope of hidden value is to the next page.

=> It is not display in URL.

e) Control State : Control State is used to manage the state of Custom Controls we used Control State.


2.  Server Side State Management : Server Side State Management is used to used the Server Resources.

=> No login on Server if they donot know the Username and password.
=> It is Secure.
=> It is slower as compared to Client side because Information comes from Server to Client then it takes time.

Types of Server Side State Management :

a) Application.
b) Sessions.
c) Profile.
d) Cache.

a) Application : It is a Global variable when run on server ( Ms Server, Framework, IIS).

When firstly user opens the site the Application_Start() Event fired and then Run and if other user opens, then Http Application class creates their instances and if all users log-out including last one and then App_End() event fired and then all instances closed or removed.

Application Variable : In the application variable we can store String value as well as objects.

=>Scope : Throughout the application means we used in whole project.

=> Hit Counter : Number of Viewer visit in our personal website with the help of an application variable.

b) Session: Session generates Unique ID for all users provides like 50 people opens and generates 50 unique Ids. It creates two session copies i.e One is stored on Server Memory and other is stored on Client Memory.
And it is stored in special type cookie i.e Session Cookie.

=> Size of Session Id is 128 bit.

In ASP.Net we can create cookieless application means if session cookie is disabled and then it pass from querystring.

=> Session Variable : In session variable we can store String value as well as Objects.

=> Scope: Throughout the session.

=> Session Expired Forcefully by using Session.Abondoned() Method in c#.

=> Expiry Time : Session Expiry Time is by default 20 minutes but we can Increase or Decrease Session Expiry time.

Types of sessions:

a) In-Process.
b) Out-Process.

a) In-Process: To store session on same process where the application is running.

Drawback :

=> If you reset the webserver i.e  IIS then Session destroy. We have single Mode in IN-PROCESS i.e INPROC and it is by default.

b) OUT-PROCESS : To store session on different  process means application is on one server and session is on other server.

Different process may be on different server. Different process may be Sql Server Database. If application close then Session not close for example, ATM Transaction Rectify.

Two types of modes :

a) State Server.
b) Sql Server.

a) State Server : To store session on different server. First you must start the ASP.NET STATE SERVICES to implement the STATE SERVER TECHNIQUE.

Drawback: If you Reset the ASP.NET State Services then session will be destroy.

b) Sql Server : We can store Session in Sql Server Database.

Two types of Database :

(A) Temporary Database.
(B) ASP State.

(A) Temporary Database: We can store Session Temporary and it is inbuilt Sql Server.

Drawback : If we Reset the Sql Server Service then Data loss from temporary database.

(B) ASP State: Session stores permanently in ASP State. If either application close or session close then there is no effect.

** SESSION_END() EVENT NOT FIRE IN OUT-PROCESS means SESSION EXPIRE BUT EVENT DIDNOT FIRE.

No comments:

Post a Comment