a blog for those who code

Saturday, 8 November 2014

Asp Net Interview Questions and Answers - Part 2

This post is continuation of Asp Net Interview Questions and Answers - Part 1, where you will find Interview Questions for Mid-Level Developer in Dot Net.

1. What are the different ASP.Net page life cycle events?
The sequence of events that take place in the life cycle of a ASP.Net web page are :
PreInit : It checks IsPostBack property and determines whether the page is loaded for the first time or it is a postback. This event also sets theme and master page dynamically.
Init : This event is used to initialize control properties.
InitComplete : Tracking of View State is turned on in this event.
PreLoad : This event loads View State for itself as well as for all the controls in the page.
Load : In this event all the controls View State and their posted values are accessible.
LoadComplete : This event is an indication that all the controls are loaded into the page.
PreRender : This event can be used to perform any updates before the output is rendered.
PreRenderComplete : This event is an indication that the PreRender event is completed for all the controls.
SaveStateComplete : This event is raised after the Control State and View State information is saved.
Unload : This event can be used to free all the resources and references.

2. What is impersonation in ASP.Net?
According to MSDN, Impersonation is when ASP.Net executes code in the context of an authenticated and authorized client. In simple terms by using Impersonation we can impersonate an aspnet account to another account that has access to resources, which are not granted to an aspnet account.
<identity impersonate="true" username="name" password="passwo"/>

3.What are the different types of Validation Controls in ASP.Net?
ASP.Net provides a range of validation controls, they are :
RequiredFieldValidator : It validates required input value.
RangeValidator : It validates the range of the input value.
CompareValidator : It compares the input input with another value.
RegularExpressionValidator : It validates the input value against a defined regular expression pattern.
CustomValidator : It allows to customize the validation logic.
ValidationSummary : It displays all errors on page collectively.

4. Describe State Management in ASP.Net?
State management means to preserve the state of a control, web page or user in the application. HTTP is a stateless protocol, that means whenever the page is posted to the server, the state of controls are lost.
So, maintaining a state is important in any web application. There are two types of State Management in ASP.Net. They are :
Client Side : Hidden Field, View State, Cookies and Query Strings.
Server Side : Session and Application

Client Side

Hidden Field : Its an Asp.Net control which is used to store small amounts of data on the client. The importance of Hidden Field is that this control is not rendered to the client and its invisible on the browser.
Use : <asp:HiddenField ID="HiddenField1" runat="server" />
View State : View State provides page level state management i.e. state is available on the current page but lost during redirect to new page. That means the data can be preserved during postbacks using View State. It can store any type of data. View State can be enabled for all server side controls with a property EnableViewState (set to true). 
Cookies : A cookie is a small file that stores user data in the user's browser. The server sends a cookie with every response which is stored in the client's browser, so that if the client request for the same page as before the user's data will be used from that cookie itself.
There are two types of cookies, and they are Persistence Cookies and Non-Persistence Cookies.
Persistence Cookies : In this type of cookies you can set an expiry date. These cookies will be stored in the hard disk till that time.Non-Persistence Cookies : When user closes the browser, these type of cookies will be lost as they are not stored in the user hard disk.
Query String : Query String is passed in the URL. They store the value in the form of Key-Value pair. For example, when redirecting a request from one page to another, you can pass the Query String as shown below, Response.Redirect("index.aspx?id=1");
The problem with Query Strings is that, the query values are exposed to the internet via URL so in some cases security might  be an issue. Also most browsers impose a 255-character limit on the length of the URL.

Server Side

Session : Session provides a facility to store information into the server memory. The server maintains the state of the user information by using a Session ID. Session object is a per-client basis, that means different client generates different session objects.
Ex : Session["UserId"] = 1; // to store in session object.
Application : The application object provides a mechanism for storing data that is accessible to all code running within the web application. Is is also called application level state management.
Ex : Application["PageViews"] = 0;

5. Explain the usage of Global.asax?
Global.asax file is an ASP.Net application file. It is used to serve application level and session level events. It is a file that contains code for responding to application-level events raised by Asp.Net or by HTTP-modules.
The important events which can be written in Global.asax files are : 
Application_Init (Fires for the first time when the application is initialized), Application_Start (Fires on Application Start), Application_End (Fires on Application End), Session_Start (Fires on Session Start), Session_End(Fires on Session End).
Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment

Contact Us


Email *

Message *


Best Hosting Plans

CC License