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.