Asp.net state management interview questions and Answers part 4
How to store and retrieve values from session?
quite simple and similar to view state in asp.net. 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
What are advantages and Limitation of using Hidden fields ?
are simple to implement.
data is cached on client side they work with Web Farms.
3. All browsers support hidden field.
4. No server resources are required.
can be tampered creating a security hole.
performance decreases if you store large data, as the data are stored in
fields do not support rich structures as HTML hidden fields are only
valued. Then you have to work around with delimiters etc to handle
is how you will actually implement hidden field in a project
<asp:HiddenField ID="hiddenUserid" runat="server" />
Does the performance for viewstate vary according to User controls?
of viewstate varies depending on the type of server control to which it is
Label, TextBox, CheckBox, RadioButton, and HyperLink are server controls
perform well with ViewState. DropDownList, ListBox, DataGrid, and DataList
poor performance because of their size and the large amounts of data making
to the server.
What are advantages and disadvantages of using Cookies?
1. No server resources are required as they are
stored in client.
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,
3. Cookies can be tampered and thus creating a
4. Cookies can expire thus leading to
5. Below is sample code of implementing cookies
Benefits and limitations of using Query Strings?
query string is information sent to the server appended to the end of a page
server resources are required.
query string containing in the HTTP requests
for a specific URL.
browsers support query strings.
string data is directly visible to user thus leading to security problems.-
browsers and client devices impose a 255-character limit on URL length.
is a sample “name” and “lastName” query string passed in URL http://www.localhost.com/Address.aspx?name=nagnath
&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?
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
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:
poster = this.PreviousPage;
you can find any control from the previous page and read its state:
posterLabel = poster.findControl("myLabel");
lbl = posterLabel.Text;
cross-page post back feature also solves the problem of posting a Form to
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.
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
38. What does the
"EnableViewState" property do? Why would I want it on or off?
allows the page to save the users input on a form across postbacks.
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.
Asp.net state management interview questions and Answers part 3
Which mode is better, InProc or SQL Server, for Session State mode in
on application hosting and requirement I will explain in short advantages and disadvantages
InProc session is much much faster,
has less requirements (serialization), but unusable when you're running your
application on several web servers;
is first problem when using InProc. When using InProc mode, all sessions are
lost whenever web application restarts.
Sql session is much slower, has
object serialization requirements, but can be shared between several web
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
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
1. Reliability is first problem when using
InProc. When using InProc mode, all sessions are lost whenever web application
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
23. What are the advantages and disadvantages of Out-Proc
(StateServer) Session mode?
data separate from IIS so any issues with IIS will not hamper session data
It is useful
in web farm and web garden scenarios.
slow due to serialization and de-serialization.
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
2. Object serialization and de serialization
requires crates overhead and network traffic issue.
3. External configuration required for sql
server session state.
Where data stored with SQL server session mode?
This is beginner
level question, answer is sterilized session data stored in sql server
26 Session_End() event is supported by which
event is supported by InProc session mode only.
What are advantages and
disadvantages using view state?
1. No server resources required
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
server resources are required.
on browser compatibility
What are Session Events?
are two types of session events available in ASP.NET:
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.
What is session ID?
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
11. What is Query string?
A query string is information that is appended to the
end of a page URL.
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
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
1. It helps maintain user state and data all over the
2. It is easy to implement and we can store any kind of
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
state supports three modes:
2. State Server
3. SQL Server
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
State Server mode
1. In this
mode, the session state is serialized and stored in memory in a separate
2. State Server
can be maintained on a different system.
3. State Server
mode involves overhead since it requires serialization and de-serialization of
4. State Server
mode is slower than InProc mode as this stores data in an external process.
SQL Server Mode
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?
Identifier is used to identify session; it uses SessionID property to identify
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.
What do you understand by StateServer(Out-Proc) mode?
session mode is also called Out-Proc session mode.
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
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
Under StateServer(Out-Proc) mode the session state is managed by?>