Pages

Men

rh

7/11/2012

Interview questions on Session in Asp.Net

What is a Session?
A Session is a unique instance of the browser. A single user can have multiple instances of the browser running on his or her machine. If each instance visits your Web application, each instance has a unique session.A session starts when a user accesses a page on a Web site for the first time, at which time they are assigned a unique session ID. The server stores the user's session ID in the Session.SessionID property.

What is the default session timeout period?
20 minutes.

Where do you generally specify the Session Timeout?

You specify the Session Timeout setting in the web.config file.

Can you specify Session Timeout in a code behind file?

Yes, can specify the Session.Timeout property as shown below in a code behind file.
           Session.Timeout = 10;

How do you end a user session?

You can call the Session.Abandon() method to end a user session. If a user then tries to access a page the server will assign them a new session ID and it will clear all the previous session variables. You'll typically use Session.Abandon() on log-out pages.

What type of data can you store in Application State and Session State variables?

Application State and Session State variables are used to store data that you want to keep for the lifetime of an application or for the lifetime of a session. You can store any type of data in the Application or Session state, including objects.

Are Application State or Session State variables type safe?

No, Application and Session state variables are created on the fly, without variable name or type checking.

Do maintaining Session state affects performance?

Yes

Can you turn of Session state?

Yes, Session state can be turned off at the application and page levels.

Are Application state variables available throughout the current process?

Yes, Application state variables are available throughout the current process, but not across processes. If an application is scaled to run on multiple servers or on multiple processors within a server, each process has its own Application state.

How do you disable Session state for a Web form?

To turn Session state off for a Web form set EnableSessionState property of the Page to False.
 
How do you turn Session state off for an entire web application?
In the Web.config file, set the sessionstate tag to False.

What are Application State variables?

Application State variables are global variables that are available from anywhere in the application. All Sessions can access Application State variables.

How to add and remove data to Application State Variables?

//Code to add data to Application State
Application.Add("AppName", "Sample");

//Code to remove data from Application State

Application.Remove("AppName");


How do you remove all Application State Variables data?

//Code to remove all Application State Variables data
Application.RemoveAll();


No comments :

Post a Comment