ASP .Net Interview Question

ASP.Net Page Life Cycle Events è

At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.
Following are the page life cycle events:
  • PreInit . PreInit is the first event in page life cycle. It checks the IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls and gets and sets profile property values. This event can be handled by overloading the OnPreInit method or creating a Page_PreInit handler.
  • Init . Init event initializes the control property and the control tree is built. This event can be handled by overloading the OnInit method or creating a Page_Init handler.
  • InitComplete . InitComplete event allows tracking of view state. All the controls turn on view-state tracking.
  • LoadViewState . LoadViewState event allows loading view state information into the controls.
  • LoadPostData . during this phase, the contents of all the input fields defined with the <form> tag are processed.
  • PreLoad . PreLoad occurs before the post back data is loaded in the controls. This event can be handled by overloading the OnPreLoad method or creating a Page_PreLoad handler.
  • Load . the Load event is raised for the page first and then recursively for all child controls. The controls in the control tree are created. This event can be handled by overloading the OnLoad method or creating a Page_Load handler.
  • LoadComplete . the loading process is completed, control event handlers are run and page validation takes place. This event can be handled by overloading the OnLoadComplete method or creating a Page_LoadComplete handler.
  • PreRender . the PreRender event occurs just before the output is rendered. By handling this event, pages and controls can perform any updates before the output is rendered.
  • PreRenderComplete . as the PreRender event is recursively fired for all child controls, this event ensures the completion of the pre-rendering phase.
  • SaveStateComplete . state of control on the page is saved. Personalization, control state and view state information is saved. The HTML markup is generated. This stage can be handled by overriding the Render method or creating a Page_Render handler.
  • UnLoad . the UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for      all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed. This event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad handler.

Why we use State Management in ASP .net =>

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

Different types of States are :

Client side state management techniques
  1.           View State
  2. ·         Control State
  3. ·         Hidden fields
  4. ·         Cookies
  5. ·         Query Strings

Server side state management techniques
  1. ·         Application State
  2. ·         Session State
  3. ·         Caching
What is Inproc and Outproc Session Mode?
Read in Detail: http://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net 
InProc -  Session will reside on same computer memory where web application deployed. session kept as live objects in web server (aspnet_wp.exe). if server restarts, all session data is lost.

OutProc -  session data is stored on state server. in case of web server restart, session data is preserved.  session serialized and stored in memory in a separate process (aspnet_state.exe). State Server can run on another machine .

Difference Between PostBack and Callback -
A postback is initiated by the browser, and reloads the whole page, usually when a control on the page (e.g. a button) is changed.
A callback is initiated by java script in the page, and can load/update parts of the page, e.g. by manipulating the DOM.

Application_Start and Session_Start in Global.aspx

Applictaion_start event fires only once in the applictaion. This firest when the applictaion start, meaning when the first reuqest for the applictaion is recieved. Session_start event is fired every time a new sesison is created. Session_start might fire many number of time in an applictaion life cycle.


Application_start is fired once when the asp.net server application starts - you can use it to set global "application" level variables which are the same for every visitor.

Session_start - you don't control when it's fired, it is fired automatically when a new user visits the site, so use it to initialise "session" level variables which are unique to each visitor. 
ADO .net 
ADO.Net provides a bridge between the front end controls and the back end database. The ADO.Net objects encapsulate all the data access operations and the controls interact with these objects to display data.

The AdRotator control randomly selects banner graphics from a list, which is specified in an external XML schedule file. This external XML schedule file is called the advertisement file.

MultiView and View controls allow you to divide the content of a page into different groups, displaying only one group at a time. Each View control manages one group of content and all the View controls are held together in a MultiView control.

The Panel control works as a container for other controls on the page.

AJAX stands for Asynchronous JavaScript and XML. This is a cross platform technology which speeds up response time.

Caching is a technique of storing frequently used data/information in memory, so that, when the same data/information is needed next time, it could be directly retrieved from the memory instead of being generated by the application.

A web service is an web application which is basically a class consisting of methods that could be used by other applications.

In which event are the controls fully loaded?
Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init 
events but you will see that view state is not fully loaded during this event.

How can we identify that the Page is Post Back?
Page object has an "IsPostBack" property, which can be checked to know that is the page posted back.

What is AutoPostBack?
If you want a control to postback automatically when an event is raised, you need to set the AutoPostBackproperty of the control to True.

The Query String helps in sending the page information to the server.

What is the difference between authentication and authorization?
Authentication verifies the identity of a user and authorization is a process where you can check whether or not the identity has access rights to the system.
In other words, you can say that authentication is a procedure of getting some credentials from the users and verify the user's identity against those credentials. 
Authorization is a procedure of granting access of particular resources to an authenticated user. You should note that authentication always takes place before authorization.

Globalization is the process of designing and developing applications that function for multiple cultures.
Localization is the process of customizing your application for a given culture and locale.
To Set a culture info use- using System.Threading; using System.Globalization; namespace
and Code is:

Thread.CurrentThread.CurrentCulture = new CultureInfo('en-US'); // for english
Thread.CurrentThread.CurrentUICulture = new CultureInfo('en-US'); 
//ja-JP for japanese, zh-CN for Chinese

Web is Stateless. It means a new instance of the web page class is re-created each time the page is posted to the server. As we all know HTTP is a stateless protocol, its can't holds the client information on page.
         
To overcome this problem ASP.NET 2.0 Provides some features like View State, Cookies, Session, Application objects 
etc. to manage the state of page.

View State = View State is one of the most important and useful client side state management mechanism. It can store the page value at the time of post back (Sending and Receiving information from Server) of your page. 

ViewState["Var"]=Count;    // to store data in viewstate
string Test=ViewState["Var"];     // to get  data from viewstate

The Response.Write() method allows you to write the normal output; whereas, the Response.Output.Write() method allows you to write the formatted output.

Differentiate between client-side and server-side validations in Web pages.
Client-side validations take place at the client end with the help of JavaScript and VBScript before the Web page is sent to the server. On the other hand, server-side validations take place at the server end.

What is the default timeout for a Cookie?
The default time duration for a Cookie is 30 minutes.

 What is the use of PlaceHolder control? Can we see it at runtime?
The PlaceHolder control acts as a container for those controls that are dynamically generated at runtime. We cannot see it at runtime because it does not produce any visible output. It used only as a container.

What setting must be added in the configuration file to deny a particular user from accessing the secured resources?
To deny a particular user form accessing the secured resources, the web.config file must contain the following code: 

<authorization >
<deny users="username" />
</authorization>

What are the event handlers that can be included in the Global.asax file?
The Global.asax file contains some of the following important event handlers:
  • Application_Error
  • Application_Start
  • Application_End
  • Session_Start
  • Session_End
Describe the complete lifecycle of a Web page.
When we execute a Web page, it passes from the following stages, which are collectively known as Web page lifecycle:
Page request, Start, Page Initialization , Load, Validation , Postback event handling, Rendering ,Unload.

How can you assign page specific attributes in an ASP.NET application?
The @Page directive is responsible for this.

Which method is used to post a Web page to another Web page?
The Respose.Redirect method is used to post a page to another page, as shown in the following code snippet: Response.Redirect("DestinationPageName.aspx");

What are Custom User Controls in ASP.NET?
The custom user controls are the controls that are defined by developers. These controls are a mixture of custom behavior and predefined behavior. These controls work similar to other Web server controls.

In which database is the information, such as membership, role management, profile, and Web parts personalization, stored?
The aspnetdb database  stores all information.

The trip of a Web page from the client to the server and then back to the client is known as a Round trip.

What is the appSettings Section in the web.config file?
The web.config file sets the configuration for a Web project. The appSettings block in configuration file sets the user-defined values for the whole application.

For example, in the following code snippet, the specified ConnectionString 
section is used throughout the project for database connection:

<configuration>
<appSettings>
<add key="ConnectionString" value="server=indiabixserver; pwd=dbpassword; database=indiabix" />
</appSettings>
...

A Web form belongs to the System.Web.UI.Page class.

HTML Server Controls: There aren't any "HTML server controls" but u can make a html control as html server control by runat property in ASP.Net. for this you have to add a runat="server" attribute to the HTML element.

The EnableViewState property enables the ViewState property on the page. If you want to store information in the viewstate then You have to set EnableViewState property to true.

The Page_Load event determines that all the controls on the page are fully loaded. But in the Page_Init event the ViewState property does not load completely .

 What is Role-based security?
In the Role-based security, you can assign a role to every user and grant the privilege according to that role. A role is a group of principal that restricts a user's privileges.

What is the difference between HTML and Web server controls?
HTML controls are client-side controls; therefore, all the validations for HTML controls are performed at the client side. On the other hand, Web server controls are server-side controls; therefore, all the validations for Web server controls are performed at the server side.

What is the use of the <sessionState> tag in the web.config file?
The <sessionState> tag is used to configure the session state features. To change the default timeout, which is 20 minutes, you have to add the following code snippet to the web.config file of an application: <sessionState timeout="40"/>

The Session.Abandon() method kills the user session explicitly.

You can prohibit a validation control to validate data at the client side by setting the EnableClientScript property to False.

Cross Page Posting  :- ASP.NET by default, submits the form to the same page. Cross page posting is submitting the form to a different page.
Two ways to use cross page posting, first way is you need to set the PostBackUrl property of the control, which specifies the target page. In the target page, you can access the PreviousPage property. For this, you need to use the @PreviousPage Type directive. You can access the controls of previous page by using the FindControl() method.
for more : Click me!

Difference between GridView and Repeater Control

A GridView displays your data source in an HTML table and extends it to allow paging, sorting, editing etc.  A repeater is a template control, where you specify the html that is used to render each row.  A gridview can only show your data in a table, but a repeater can show your data in any way you want by creating the relevant ItemTemplate.  For example you might show a list of products, with each product having an image, description, list of colours, price etc, all arranged as you'd normal see a product listing.  A repeater can supply that kind of display flexibility.

Difference between Response.Redirect and Server.Transfer
1- Server.transfer is Application Level while Response.Redirect is Server Level.
2- Their is no round trip in Server.transfer , where as in Response.Redirect thier is a single  Round trip. 
3- Response.redirect is slow as it makes round trip to the server where as server.tranfer is fast compared to it 
4- Response.Redirect will change browser current url and update history where as server.tranfer does not change browser current url .
5- Using server.tranfer we can access previous Page Control’s Data.

Partial Class

A class defined in  two or more files is called a partial class. It Allows more than one developers to work simultaneously on the same class. During compile time all the partial class are compiled into one type only.


Http GET and POST

The Hypertext Transfer Protocol (HTTP) is a communication protocol that is designed to enable request-response between clients and servers.

Two HTTP Request Methods: GET and POST

Get:

This method appends form data to page request URL as query string.
We can access query string in ASP.NET using Request.QueryString["key1"].
we should not use GET() if data needs Security.
GET requests can be cached.
GET requests remain in the browser history.
GET requests have length restrictions

Post:

POST method transfers information over HTTP headers.
We can access form data in ASP.NET using Request.Form["key1"].
Post() Secure in compare to GET().
POST requests are never cached.
POST requests do not remain in the browser history.
POST requests have no restrictions on data length


What is Machine.config, Web.config, App.config


Machine.config file stores configuration information at system level. It can contain configuration information like timeout in ASP.NET application, requestLimit, memoryLimit, and ClientConnectedCheck etc.

Generally we have two kinds of application web application and windows application. Web.config file stores configuration data for web applications and app.config file store configuration information for windows application.

Difference between Application and Session State
Session variable are only available at the user level means no user can access the other user session variables.
Application variable is available at application level means every user of the application can access the same application variable.

What is event bubbling?

Server controls like Data grid, Data List, and Repeater can have other child controls inside them. Example Data Grid can have combo box inside data grid. These child control do not raise there events by themselves, rather they pass the event to the container parent (which can be a data grid, data list, repeater), which passed to the page as “ItemCommand” event. As the child control send events to parent it is termed as event bubbling.

HttpHandler and HttpModule 

The prime  and common goal of HttpHandler and httpModule is to inject pre-processing logic before the ASP.NET request reaches to  server.

Why : Many times we want to implement pre-processing logic before a request  hits the Server  resources. So, to implement this by using  HttpModule and HttpHandler.

HttpHandler - The Extension Based Preprocessor
HttpHandlers are nothing but classes which have pre-processing logic implemented, that is executed based on the extension of the file name requested before the request goes to server .

HttpModule The Event Based Preprocessor
HttpModule is an event based methodology to inject pre-processing logic before any resource is requested. When any client sends a request for a resource, the request pipeline emits a lot of events like: BeginRequest, AuthenticateRequest, AuthorizeRequest, PreRequestHandlerExecute, PostRequestHandlerExecute, EndRequest.

So when the request pipe line executes, the logic from the modules is processed. Modules are called before and after the handler executes.

Download a Demo that implements HttpHandlers and HttpModule Click here .

Reference: http://www.codeproject.com/Articles/335968/Implementing-HTTPHandler-and-HTTPModule-in-ASP-NET 

for More Interview Questions : Click @ me !

2 comments:

Topics

ADO .Net (2) Ajax (1) Angular Js (17) Angular2 (24) ASP .Net (14) Azure (1) Breeze.js (1) C# (49) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DI (3) Dotnet (21) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (9) Lamda (3) Linq (11) Mongodb (1) MVC (48) NodeJS (7) RDLC (1) Report (1) Sql Server (29) SSIS (3) SSRS (2) UI (1) WCF (12) Web Api (10) Web Service (1) XMl (1)