Monday 15 December 2014

ASP.NET Interview Question

What is ASP.NET? 
ASP.NET is a specification developed by Microsoft to create dynamic Web applications, Web sites, and Web services. It is a part of .NET Framework. You can create ASP.NET applications in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages, such as VBScript. The Web Forms support to create powerful forms-based Web pages. You can use ASP.NET Web server controls to create interactive Web applications. With the help of Web server controls, you can easily create a Web application.

What is ASP.NET page life cycle? Also describe the page life cycle events.
In ASP.NET, when we execute a Web page, it passes through the following stages, which are known as Web page lifecycle.
1.  Init ( page Initialisation)
2.  Load
3.  Render
4.  Unload

And these stages can be further classified into different page life cycle events. Which are following :

Init (Page Initialisation):

a. PreInit :  During this stage, ASP.NET makes sure the page either parsed or compiled and a cached version of the page can be sent in response. During this stage sets the Request and Response page properties and the page check the page request is either a postback or a new request
b. Init : During this stage, the page initialize and the control's Unique Id property are set.
c. Init Complete : It indicates that page identification completed and initialized.

Load : During this stage, if the request is postback, the control properties are loaded without loading the view state and control state otherwise loads the view state. Its events can be classified as follows:
a. Preload
b. Load
c. Load Complete

Validation: During this stage, the controls are validated.

Postback event handling : During this stage, if the request is a postback, handles the event.

Render :  During this stage, the page invokes the render method to each control for return the output. At this stage all the Asp.net control converts into HTML control and loads the .dll of the website or an application.

Unload:  During this stage, When the page is completely rendered and sent to the client, the page is unloaded.

What is State Management? How many ways are there to maintain a state in .NET? 
State management is used to store information requests. The state management is used to trace the information or data that affect the state of the applications. There are two ways to maintain a state in .NET, Client-Based state management and Server-Based state management. The following techniques can be used to implement the Client-Based state management:
1. View State
2. Hidden Fields
3. Cookies
4. Query Strings
5. Control State

The following techniques can be used to implement Server-Based state management:
1. Application State
2. Session State

What is IIS? 
Internet Information Services (IIS) is created by Microsoft to provide Internet-based services to ASP.NET Web applications. It makes your computer to work as a Web server and provides the functionality to develop and deploy Web applications on the server. IIS handles the request and response cycle on the Web server. It also offers the services of SMTP and FrontPage server extensions. The SMTP is used to send emails and use FrontPage server extensions to get the dynamic features of IIS, such as form handler.

What is Query String? What are its advantages and limitations? 
The Query String helps in sending the page information to the server. The Query String has the following advantages:
1. Every browser works with Query Strings.
2. It does not require server resources and so does not exert any kind of burden on the server.

The following are the limitations of Query String:
1. Information must be within the limit because URL does not support many characters.
2. Information is clearly visible to the user, which leads to security threats.

What is actually returned from server to the browser when a browser requests an .aspx file and the file is displayed?
When a browser requests an .aspx file then the server returns a response, which is rendered into a HTML string.

How can you display all validation messages in one control?
The ValidationSummary control displays all validation messages in one control.
Which two new properties are added in ASP.NET 4.0 Page class? The two new properties added in the Page class are MetaKeyword and MetaDescription.

What is tracing? Where is it used? 
Tracing displays the details about how the code was executed. It refers to collecting information about the application while it is running. Tracing information can help you to troubleshoot an application. It enables you to record information in various log files about the errors that might occur at run time. You can analyze these log files to find the cause of the errors. In .NET, we have objects called Trace Listeners. A listener is an object that gets the trace output and stores it to different places, such as a window, a file on your locale drive, or a SQL Server. The System.Diagnostics namespace contains the predefined interfaces, classes, and structures that are used for tracing. It supplies two classes, Trace and Debug, which allow you to write errors and logs related to the application execution. Trace listeners are objects that collect the output of tracing processes.

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.

How can you register a custom server control to a Web page? 
You can register a custom server control to a Web page using the @Register directive.

Which ASP.NET objects encapsulate the state of the client and the browser?
The Session object encapsulates the state of the client and browser.

Differentiate globalization and localization. 
The globalization is a technique to identify the specific part of a Web application that is different for different languages and make separate that portion from the core of the Web application. The localization is a procedure of configuring a Web application to be supported for a specific language or locale.

What is ViewState? 
The ViewState is a feature used by ASP.NET Web page to store the value of a page and its controls just before posting the page. Once the page is posted, the first task by the page processing is to restore the ViewState to get the values of the controls.

Which method is used to force all the validation controls to run? 
The Page.Validate() method is used to force all the validation controls to run and to perform validation.

Which method has been introduced in ASP.NET 4.0 to redirect a page permanently?
The RedirectPermanent() method added in ASP.NET 4.0 to redirect a page permanently. The following code snippet is an example of the RedirectPermanent() method: RedirectPermanent("/path/Aboutus.aspx");

How can you send an email message from an ASP.NET Web page?
You can use the System.Net.Mail.MailMessage and the System.Net.Mail.SmtpMail classes to send an email in your Web pages. In order to send an email through your mail server, you need to create an object of the SmtpClient class and set the server name, port, and credentials.

What is the difference between the Response.Write() and Response.Output.Write() methods?
The Response.Write() method allows you to write the normal output; whereas, the Response.Output.Write() method allows you to write the formatted output.

What does the Orientation property do in a Menu control? 
Orientation property of the Menu control sets the horizontal or vertical display of a menu on a Web page. By default, the orientation is vertical.

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.

How does a content page differ from a master page?
A content page does not have complete HTML source code; whereas a master page has complete HTML source code inside its source file.
Suppose you want an ASP.NET function (client side) executed on the MouseOver event of a button.

Where do you add an event handler?
The event handler is added to the Add() method of the Attributes property.

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

What are HTTP handlers in ASP.NET?
HTTP handlers, as the name suggests, are used to handle user requests for Web application resources. They are the backbone of the request-response model of Web applications. There is a specific event handler to handle the request for each user request type and send back the corresponding response object. Each user requests to the IIS Web server flows through the HTTP pipeline, which refers to a series of components (HTTP modules and HTTP handlers) to process the request. HTTP modules act as filters to process the request as it passes through the HTTP pipeline. The request, after passing through the HTTP modules, is assigned to an HTTP handler that determines the response of the server to the user request. The response then passes through the HTTP modules once again and is then sent back to the user. You can define HTTP handlers in the <httpHandlers> element of a configuration file. The <add> element tag is used to add new handlers and the <remove> element tag is used to remove existing handlers. To create an HTTP handler, you need to define a class that implements the IHttpHandler interface.

What are the events that happen when a client requests an ASP.NET page from IIS server?
The following events happen when a client requests an ASP.NET page from the IIS server:
1. User requests for an application resource.
2. The integrated request-processing pipeline receives the first user request.
3. Response objects are created for each user request.
4. An object of the HttpApplication class is created and allocated to the Request object.
5. The HttpApplication class processes the user request.

Explain file-based dependency and key-based dependency. 
In file-based dependency, you have to depend on a file that is saved in a disk. In key-based dependency, you have to depend on another cached item.

How can you implement the postback property of an ASP.NET control?
You need to set the AutoPostBack property to True to implement the PostBack property of controls.

Explain how Cookies work. Give an example of Cookie abuse.
The server tells the browser to put some files in a cookie, and the client then sends all the cookies for the domain in each request. An example of cookie abuse is large cookies affecting the network traffic.

Explain login controls. 
Login controls are built-in controls in ASP.Net for providing a login solution to ASP.NET application. The login controls use the membership system to authenticate a user credentials for a Web site. There are many controls in login controls.
1. ChangePassword control - Allows users to change their password.
2. CreateUserWizard control - Provides an interface to the user to register for that Web site.
3. Login control - Provides an interface for user authentication. It consists of a set of controls, such as TextBox, Label, Button, CheckBox, HyperLink.
4. LoginView control - Displays appropriate information to different users according to the user's status.
5. LoginStatus control - Shows a login link to users, who are not authenticated and logout link, who are authenticated
6. LoginName control - Displays a user name, if the user logs in.
7. PasswordRecovery control - Allows users to get back the password through an e-mail, if they forget.

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:
1. Application_Error
2. Application_Start
3. Application_End
4. Session_Start
5. Session_End

What is the difference between page-level caching and fragment caching?
In the page-level caching, an entire Web page is cached; whereas, in the fragment caching, a part of the Web page, such as a user control added to the Web page, is cached.

List of all templates of the Repeater control.
The Repeater control contains the following templates:
1. ItemTemplate
2. AlternatingltemTemplate
3. SeparatorTemplate
4. HeaderTemplate
5. FooterTemplate


No comments:

Post a Comment