Monday, 17 March 2014

Interview Q & A on State Management in Asp.Net(Part 2)

1): What is State management in ASP.NET?

Ans : State management is the process by which you maintain state and page information over multiple requests for the same or different pages.

2): What are the advantages and disadvantages of using client side state management?

Ans : Advantages:
No server resources are required.
Simple implementation

Disadvantages:
Performance considerations
Potential security risks
Depends on browser compatibility

3): Why we need State management to maintain state?

Ans : Net Pages are destroyed and re-created with each round trip to the server; therefore, page information will not exist beyond the life cycle of a single page.

4): Is ViewState encoded?

Ans :Yes, ViewState is base-64 encoded.

5): What happens during the Page_Init event?

Ans : The server controls are loaded and initialized from the Web form’s view state. This is the first step in a Web form’s life cycle.

6): How do you enable or disable a ViewState for a control on the page?

Ans : Every ASP.NET control has a property called Enable ViewState. If Enable ViewState is set to true ViewState is enabled for the control. If Enable ViewState is set to false ViewState is disabled for the control.

7) : How do you enable or disable a ViewState at the page level?

Ans : At the page level you can enable or disable ViewState using EnableViewState property of the page.

8): What is the name of the hidden form field in which ViewState of the page is saved?

Ans : _ViewState

9) : Give an example to send Query Strings from code?

Ans : You can send query strings from server side code using the Response.Redirect() method as shown below.

Response.Redirect("QueryStrings2.aspx?FName=David&LName=Boon");

10): When does ViewState restoration happens?

Ans : During the Page_Init event.

11) : How do you create a Cookie that never expires?

To create a Cookie that never expires, set the Expires property of the Cookie object to DateTime.MaxValue. 

myCookie.Expires = DateTime.MaxValue;

12) :What is Session Identifier?
Ans: Session Identifier is used to identify session. It has SessionID property. 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. 

13)Q : What is the default  session timeout period? Where do u generally specify the Session Timeout?

 Ans: The default session timeout period is 20 minutes. You specify the session timeout setting in the web.config file.

14) : What is a Session?

Ans : 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.

15) : What is the default session timeout period?

Ans : 20 minutes.

16) : Where do you generally specify the Session Timeout and Can you specify Session Timeout in a code behind file?

Ans : You specify the Session Timeout setting in the web.config file and Yes,we can specify the Session.Timeout property as shown below in a code behind file.
 Session.Timeout = 10;

17) : How do you end a user session?

Ans : 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.


18) : How do you turn Session state off for an entire web application?

Ans : In the Web.config file, set the sessionstate tag mode to False.

19) : What are Application State variables?

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

20) : How to add and remove data to Application State Variables?

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

//Code to remove data from Application State
Application.Remove("AppName");

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


21) : What are different state management techniques available in .Net?

Ans : ASP.NET provides multiple ways to maintain state between server round trips this can be either client side or server side.

Client Side State Management options:

Storing page information using client-side options doesn't use server resources.
1. View state
2. Control state
3. Hidden fields
4. Cookies
5. Query strings

Server side state management options:

1. Application state
2. Session state

22) : What are Cookies in ASP.NET?

Ans : Cookies are small pieces of information stored on the client computer.Use cookies to store small amounts of information on the client’s machine. Web sites often use cookies to store user preferences or other information that is client-specific.

23) : What are different types of Cookies?

Ans : Persistant cookie and non persistant cookie.

• In-memory cookies: An in-memory cookie goes away when the user shuts the browser down.
• Persistent cookies: A persistent cookie resides on the hard drive of the user and is retrieved when the user comes back to the Web page.

24) : What are Session Cookies?

Ans : Session cookies are stored in-memory during the client browser session. When the browser is closed the session cookies are lost.

25) : How can you create Session Cookies?

Ans : You can create session cookies by calling the Add method of the Cookies collection on the Response object. The Cookies collection contains individual cookie objects of type HttpCookie.

//Code to create a UserName cookie containing the name David.
HttpCookie CookieObject = new HttpCookie("UserName", "David");
Response.Cookies.Add(CookieObject);

//Code to read the Cookie created above Request.Cookies["UserName"].Value;

26) : What are Persistent Cookies used for?

Ans : Persistent cookies are generally used to store information that identifies a returning user to a Web site. Typical information found in Persistent Cookies includes user names or user IDs.

27) : How do you create a Persistent Cookie?

Ans : You create a persistent cookie the same way as session cookies except that you set the Expires property to a Date in the future which will store the Cookie to the client computer harddrive.

//Code to create a UserName Persistent Cookie that lives for 10 days
HttpCookie CookieObject = new HttpCookie("UserName", "David");
CookieObject.Expires = DateTime.Now.AddDays(10);
Response.Cookies.Add(CookieObject);

//Code to read the Cookie created above
Request.Cookies["UserName"].Value;

28) : What is Cookie Dictionary?

Ans :A cookie dictionary is a single cookie object that stores multiple pieces of information. You use the Values property to access and assign new values to the cookie dictionary.

29) : How do you create a Cookie that never expires?

Ans :To create a Cookie that never expires set the Expires property of the Cookie object to DateTime.MaxValue.

30) :What is IIS Activation Mode?
Ans:Any project registered with IIS is implicitly starteds when it is not running and it also ends the application based on Timeout & Other Dependencies.




















No comments:

Post a Comment