Saturday, August 4, 2012

Interview Questions Of ASP.NET - I

Que. 1. Explain the Life Cycle of an ASP.NET page?

Ans. 
Following are the events occur during ASP.NET Page Life Cycle:
  1. Page_PreInit
  2. Page_InitPage_InitComplete
  3. Page_PreLoad
  4. Page_Load
  5. Control Events
  6. Page_LoadComplete
  7. Page_PreRender
  8. SaveViewState
  9. Page_Render
  10. Page_Unload
Note : Among above events Page_Render is the only event which is raised by page. So we can't write code for this event. 
Que. 2 . How does the cookies work in asp.net?  
Ans. 
As we know that Http is an State-Less Protocol which is required for interaction between client and server .
So there is a need to remember state of request raised by an web browser so that web server can recognize you have already previously visited or not.

There are two types of State Management Techniques:
  • Client side state management
  • Server - side state management

Using cookies comes under client side state management. In HttpResponse we write
Cookie containing sessionId and other information within it.

When a browser made a request to the web server the same cookie is sent to the server where server recognize the session id and get other information stored to it previously.

Que. 3. What is boxing and unboxing?
Ans.
Boxing is that happens when a value-type object is assigned to a reference-type variable.

Unboxing is what happens when a reference-type variable is assigned to a value-type variable.

            For Eg.
            int foo = 42; // Value type.
            object bar = foo; // foo is boxed to bar.
            int foo2 = (int)bar; // Unboxed back to value type.
 Note :Boxing is may be Implicit whenever unboxing is explicit conversion.
  
Que. 4. What is Url-Rewriting?
 Ans.
 URL rewriting is the process of intercepting an incoming Web request and redirecting the request to a different resource. When performing URL rewriting, typically the URL being requested is checked and, based on its value, the request is redirected to a different URL.
For eg. i want to access http://mywebsite.com/college.aspx?id=12 now by i want url to be http://mywebsite.com/college/12 displayed.
That can be do by Url Rewriting.


Que. 5. What are Inproc and Outproc?
 Ans.

Session state can be configured using the <sessionState> section in the application's web.config file. Hence, we can increase the default Session timeout value to our desired value using the following statement in the web.config file.

    <sessionState  
    mode = <"inproc" | "sqlserver" | "stateserver">
    cookieless = <"true" | "false">
    timeout = <positive integer indicating the session timeout in minutes>
    sqlconnectionstring = <SQL connection string that is only used in the SQLServer mode>
    server = <The server name that is only required when the mode is State Server>
     port = <The port number that is only required when the mode is State Server>
/>

The following section discusses each of the settings shown in Listing 1 earlier, in detail.

Mode: This setting supports three options.  They are inproc, sqlserver, and stateserver.

ASP.NET supports two modes: in process and out of process.

There are also two options for out-of-process state management:
  1. Memory based (stateserver) and 
  2. SQL Server based (sqlserver).

Cookieless: This setting takes a boolean value of either true or false to indicate whether the Session is a cookieless one.

Timeout: This indicates the Session timeout vale in minutes.  This is the duration for which a user's session is active.  Note that the session timeout is a sliding value; on each request the timeout period is set to the current time plus the timeout value.

SqlConnectionString: This identifies the database connection string that names the database used for mode sqlserver.

Server: In the out-of-process mode stateserver, it names the server that is running the required Windows NT service: ASPState.

Port: This identifies the port number that corresponds to the server setting for mode State Server.  Note that a port is an unsigned integer that uniquely identifies a process running over a network.


As Stated Earlier, Session state in ASP.NET can be stored in one of the following three ways.
  1. InProc
  2. State Server
  3. SQL Server