Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post state management interview questions and Answers part 4 state management interview questions and Answers part 4

31.  How to store and retrieve values from session?

Its quite simple and similar to view state in We can interact with session state with the System.Web.SessionState.HttpSessionState class, because this provides the built-in session object in ASP.NET pages.

 //Storing UserName in Session
  Session["UserFullName"] =txtFullName.Text;


32.  What are advantages and Limitation of using Hidden fields ?


 1.  They are simple to implement.
 2.  As data is cached on client side they work with Web Farms.
 3. All browsers support hidden field.
4.  No server resources are required.


1. They can be tampered creating a security hole.
2. Page performance decreases if you store large data, as the data are stored in
pages itself.
3. `Hidden fields do not support rich structures as HTML hidden fields are only
single valued. Then you have to work around with delimiters etc to handle
complex structures.
4. Below is how you will actually implement hidden field in a project
<asp:HiddenField ID="hiddenUserid" runat="server" />


33.  Does the performance for viewstate vary according to User controls?

Performance of viewstate varies depending on the type of server control to which it is
applied. Label, TextBox, CheckBox, RadioButton, and HyperLink are server controls
that perform well with ViewState. DropDownList, ListBox, DataGrid, and DataList suffer
from poor performance because of their size and the large amounts of data making
roundtrips to the server.


34.  What are advantages and disadvantages of using Cookies?


1.  No server resources are required as they are stored in client.
2. They are light weight and simple to use


1.  Most browsers place a 4096-byte limit on the size of a cookie, although support  for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.
2.  Some users disable their browser or client device’s ability to receive cookies,
There by limiting the use of cookies.
3.  Cookies can be tampered and thus creating a security hole.
4.  Cookies can expire thus leading to inconsistency.
5.  Below is sample code of implementing cookies
Request.Cookies.Add(New HttpCookie(“name”, “usrname”))


35. Benefits and limitations of using Query Strings?

A query string is information sent to the server appended to the end of a page URL.


1. No server resources are required.
2. The query string containing in the HTTP requests for a specific URL.
3. All browsers support query strings.


1. Query string data is directly visible to user thus leading to security problems.-
Most browsers and client devices impose a 255-character limit on URL length.
2. Below is a sample “name” and “lastName” query string passed in URL &lastName=kendre . This query string data can then be requested later by using


36. How do we access viewState value of this page in the next page?

View state is page specific; it contains information about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name, __POSTBACK . This field is embedded only when there is an IButtonControl on thepage and its PostBackUrl property is set to a non-null value. 

This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new PreviousPage property of the page:

Page poster = this.PreviousPage;
Then you can find any control from the previous page and read its state:
Label posterLabel = poster.findControl("myLabel");
string lbl = posterLabel.Text;
This cross-page post back feature also solves the problem of posting a Form to multiple
pages, because each control, in theory, can point to different post back URL.


37. Can we post and access view state in another application?

 You can post back to any page and pages in another application, too. But if you are posting pages to another application, the PreviousPage property will return null.

This is a significant restriction, as it means that if you want to use the view state, you are confined, for example, posting to pages in the same virtual directory. Even so, this is a highly acceptable addition to the functionality of ASP.NET.


38. What does the "EnableViewState" property do? Why would I want it on or off?

It allows the page to save the users input on a form across postbacks.
It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate. state management interview questions and Answers part 3 state management interview questions and Answers part 3

21.  Which mode is better, InProc or SQL Server, for Session State mode in

IT depends on application hosting and requirement I will explain in short advantages and disadvantages of both.


InProc session is much much faster, has less requirements (serialization), but unusable when you're running your application on several web servers;
Reliability is first problem when using InProc. When using InProc mode, all sessions are lost whenever web application restarts.

SQL Server: 

Sql session is much slower, has object serialization requirements, but can be shared between several web servers;

22.  What are advantages and disadvantages using InProc session sate?


1.  InProc is default session state configuration not required for State server and sql server external configuration required.
2.  You can save any object in session variable even if it is not serializable. For State and SQl server requires objects to be serializable.
3.  InProc mode works on shared web hosting. State Server is usually not allowed, and some shared web hosting providers give option to use SQL Server. In the other hand, InProc works in any hosting package.


1.  Reliability is first problem when using InProc. When using InProc mode, all sessions are lost whenever web application restarts.
2.   Scalability is one more problem when using InProc mode. Each user has its own collection of session variables. On high traffic websites, with thousands of visitors online, sesssion data easily grow and spend complete memory on web server.
3. There is a problem on web farms and web gardens. If you host website on web farm (multiple servers) or web garden (multiple processors) ASP.NET application will use multiple processes. Since InProc stores session data inside single process, session data will be lost when visitor request goes to different server or processor.


23.  What are the advantages and disadvantages of Out-Proc (StateServer) Session mode?


It keeps data separate from IIS so any issues with IIS will not hamper session data
It is useful in web farm and web garden scenarios.


Process is slow due to serialization and de-serialization.
State Server always needs to be up and running.

24 What are Advantages and disadvantages using SQL server session state?


1.  If IIS restart session data not affected /application not affected with inProc session we face this issue frequently.
2.  More Secure and reliable compared with InProc and state server.
3.  Usefull in Web farm and Web gardens scenarios.


1.  Performance issue is main disadvantage (processing is slow), with SQL server session state application is slow compared with InProc.
2.  Object serialization and de serialization requires crates overhead and network traffic issue.
3.  External configuration required for sql server session state.

25  Where data stored with SQL server session mode?

This is beginner level question, answer is sterilized session data stored in sql server database.

26  Session_End() event is supported by which mode?

Session_End() event is supported by InProc session mode only.

27.   What are advantages and disadvantages using view state?


1.  No server resources required
2. simple implementation
3. automatic retention of page and control state
4 . Enhanced security features. The values in view state are hashed, compressed, and encoded for Unicode implementations.


1.  Performance. The view state is stored in the page itself, so increase the page size.
2.  Security. The view state is stored in a hidden field on the page. Although view state stores data in a hashed format, it can be tampered with.

28.   What are the advantages and disadvantages of using client side state management?


No server resources are required.
Simple implementation


Performance considerations
Potential security risks
Depends on browser compatibility


29.   What are Session Events?

There are two types of session events available in ASP.NET:


You can handle both these events in the global.asax file of your web application. When a new session initiates, the session_start event is raised, and the Session_End event raised when a session is abandoned or expires.


30.   What is session ID?

ASP.NET uses an 120 bit identifier to track each session. This is secure enough and can't be reverse engineered. When a client communicates with a server, only the session ID is transmitted between them. When the client requests for data, ASP.NET looks for the session ID and retrieves the corresponding data.

State management interview questions part 2

State management interview questions part 2

11.  What is Query string?

A query string is information that is appended to the end of a page URL.

Example: &lastName=kendre

12.  What is application state?

Application state is a global storage mechanism that is accessible from all pages in the Web application. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages.

13.  What is Session state?

ASP.NET allows you to save values by using session state — which is an instance of the HttpSessionState class — for each active Web-application session.

14.  What is Profile Properties?

ASP.NET provides a feature called profile properties, which allows you to store user-specific data. This feature is similar to session state, except that the profile data is not lost when a user's session expires. The profile-properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user.

15.  What is Session?

As we know, HTTP is a stateless protocol; it can't hold client information on a page. Session provides a facility to store information on server memory. It can support any type of object to store along with our own custom objects. For every client, session data is stored separately, which means session data is stored on a per client basis.

16.  What are Advantages and disadvantages of Session?


1. It helps maintain user state and data all over the application.
2. It is easy to implement and we can store any kind of object.
3. Stores client data separately.
4. Session is secure and transparent from the user.


1. Performance overhead in case of large volumes of data/user, because session data is stored in server memory.
2. Overhead involved in serializing and de-serializing session data, because in the case of StateServer and SQLServer session modes, we need to serialize the objects before storing them.


17. Explain in detail Session state modes?

Session state supports three modes:

1.  InProc

2.  State Server

3.  SQL Server

InProc Mode

1. This mode stores the session data in the ASP.NET worker process.
2. This is the fastest among all of the storage modes.
3. This mode effects performance if the amount of data to be stored is large.
4. If ASP.NET worker process recycles or application domain restarts, the session state will be lost.

State Server mode

1. In this mode, the session state is serialized and stored in memory in a separate process.
2. State Server can be maintained on a different system.
3. State Server mode involves overhead since it requires serialization and de-serialization of objects.
4. State Server mode is slower than InProc mode as this stores data in an external process.

SQL Server Mode

In this storage mode, the Session data is serialized and stored in a database table in the SQL Server database.

1. This is reliable and secures storage of a session state.
2. This mode can be used in the web farms.
3. It involves overhead in serialization and de-serialization of the objects.
4. SQL Server is more secure than the InProc or the State server mode.


18. What is Session Identifier?


Session Identifier is used to identify session; it uses SessionID property to identify session.


When a page is requested, browser sends a cookie with a session identifier. This identifier is used by the web server to determine if it belongs to an existing session. If not, a Session ID (120 - bit string) is generated by the web server and sent along with the response.


19.  What do you understand by StateServer(Out-Proc) mode?

1. StateServer session mode is also called Out-Proc session mode.
2. StateServer uses a stand-alone Windows Service which is independent of IIS and can also be run on a separate server. This session state is totally managed by aspnet_state.exe.
3. This server may run on the same system, but it's outside of the main application domain where your web application is running. This means if you restart your ASP.NET process, your session data will still be alive


20.  Under StateServer(Out-Proc) mode the session state is managed by?>


< >