ASP.NET is one of the greatest framework for application development. Here is some common important interview questions and answers in ASP.NET. Hope it will help you to build successful carrier.
What is ASP?
Active Server Page or ASP is a Microsoft’s server-side technology, which helps us to create dynamic and user-friendly web pages or web sites. It is also known as Classic ASP.
What is ASP.NET?
What is the basic difference between ASP and ASP.NET?
The basic difference between ASP and ASP.NET is that ASP is interpreted and ASP.NET is compiled. This means that when we execute an ASP page, it is interpreted. On the other hand when we compile a .NET page all the source code is converted into a Microsoft Intermediate Language (MSIL). Then CLR of .NET framework converts it into machine language.
What are the Development Models in ASP.NET?
ASP.NET supports three different development models. Such:
- Web Pages
- MVC (Model View Controller)
- Web Forms
What is ASP.NET life cycle?
The ASP.NET life cycle could be divided into the following two groups:
- Application Life Cycle
- Page Life Cycle
What is asp.net application life cycle?
The asp.net application life cycle has the following stages:
- User makes a request to access application resource like page. Browser sends this request to the web server (IIS)
- When ASP.NET receives the first request for any resource, a class named Application Manager creates an application domain or app domain. Application domain is a set of boundary where the application can run.
Within the app domain an instance of the class named Hosting Environment is created. It is the name of the folder where the application is stored
- ASP.NET core objects (HttpContext, HttpRequest, and HttpResponse) are created and initialized
- An object of the HttpApplication class is created and assigned to the request
The HttpApplication object processed the request. During the processing different events are raised
What is ASP.NET Page Life Cycle?
When a page is requested by the user, it is loaded into the server memory, processed, and finally sent to the web browser. Then it is unloaded from the server memory. Each stages of the entire process several methods and events are available. We can control the default hierarchy according to our needs.
ASP.NET Page Life Cycle Events
At each stage of the page life cycle some events are raises. List the events in page life cycle are given bellow:
What are the state managements types in ASP.Net?
There are two different types of state management in ASP.Net:
- Client Side State Management
- Server Side State Management
Client Side state management use client side recourse. It does not use any server resource. Server Side state management use server side resource for store data.
What are the types of client side state management?
- View State
- Hidden Field
- Control State
What are the types of server side state managements?
- Application Object
What is view state?
View State is the most important and useful client side state management mechanisms. During the post back time It can store the page value of your page. ASP.NET pages provide the ViewState property as a built-in structure for automatically storing values between multiple requests for the same page. It only contain information about page and its controls. View State use Hidden field to store its information in a encoding format. If you run you application, In Browser, RighClick > View Source, You will get the ViewState information I hidden filed.You can enable and disable View state for a single control by changing EnableViewState Property of that control. For entire page, we need to set EnableViewState to false in the top of the page. We can turn of or on it from the web.cofig file for the entire project.
ViewState is a .Net mechanism to store data during post back. Here the state of objects is stored in a hidden field on the page and saved on client side and back to server whenever required.
add one variable in View State,
Retrieving information from View State
What are the Advantages of view state?
Easy to implement.
No server resources are required.
Improved security features, like it can be encoded and compressed.
What are the Disadvantages of view state?
It can impact the performance of the page for large amount of data.
It’s stored in a hidden filed in hashed format. So any one can easily retrieve it.
It can not be implemented for any mobile devices.
Can we have a web application running without web.Config file?
What is Protected Configuration?
It is a feature to secure connection string information.
Is it possible to create web application with both webforms and mvc?
Yes. We have to include below MVC assembly references in the web forms application to create hybrid application.
Can we add code files of different languages in App_Code folder?
No. All the code files must be in same language.
Can we have multiple web config files for an asp.net application?
What is the difference between web config and machine config?
Web config file is specific to a web application. Machine config file is specific to a machine or server. Any application can have multiple web config files. But a server can have only one machine config file.
What is the global.asax file?
Global.asax file or ASP.NET application fileis an optional file exists in the root directory. It is used to handle application events such as Application_Init, Application_Start, Application_End, Session_Start, Session_End, Application_Error, etc.
Global.asax file contains a class and represent your whole application. At runtime this file is parsed and compiled into a dynamically generated .NET Framework class derived from the HttpApplication base class. External users can not view or download it.
What is the concept of Postback in ASP.NET?
A postback is a consequent HTTP POST to the same page that the form is on. A Postback is a HTTP request sent from a client to server from the same page which is already working with. A post back is round trip from the client (Browser) to the server and then back to the client. A Postback is a request for a page that is not the first request. It will always be in response to a user action (triggered by a Button, AutoPostBack control or Ajax).
A Postback is a HTTP request from client to server for a page which is already loaded or viewing.
Postback can be either full (refresh the entire page) or partial (refresh a portion of a page where AJAX is used).
Difference between a Postback and a Callback in ASP.NET
A Callback is a special kind of Postback. In Postback the entire page is refreshed but in Callback the entire page is not refreshed. Only a part of the page is refreshed. It is occurred when we used Ajax control in our page.
Difference between ASP.NET WebForms and ASP.NET MVC?
- It uses Page controller pattern approach for rendering layout. That means every page has its own controller (code-behind page)
- Page size is big. Because it has large viewstate
- Testing is difficult
- It is good for small scale of application and limited team size
- It uses Front Controller approach. That means a common controller for all pages
- Page size is small. Because, it has no viewstate
- Testing is easy
- It is good for large scale of application with large team size.
Is ASP.NET MVC going to replace ASP.NET WebForms?
ASP.NET MVC is not replacing ASP.NET WebForms. Both development models exist and can be used to develop ASP.NET applications. Both have advantages and disadvantages.
What is the difference between custom controls and user controls?
Custom controls are basically compiled code like DLL. These can be easily added to toolbox. These can be easily used in multiple projects using drag and drop approach. These are comparatively hard to create.
User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create. In order to use them in multiple projects we need to copy and paste to the other project as well.
Difference between Response.Redirect and Server.Transfer?
Response.Redirect and Server.Transfer both are used to transfer a user from one page to another. Both have some difference.
- Response.Redirect() will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back
- It redirects the request to some plain HTML pages on our server or to some other web server
- It causes additional roundtrips to the server on each request
- It doesn’t preserve Query String and Form Variables from the original request
- It enables to see the new redirected URL where it is redirected in the browser
- Response. Redirect simply sends a message down to the browser
- Server.Transfer() does not change the address bar, we cannot hit back.One should use Server.Transfer() when he/she doesn’t want the user to see where he is going. Sometime on a “loading” type page
- It transfers current page request to another .aspx page on the same server
- It preserves server resources and avoids the unnecessary roundtrips to the server
- It preserves Query String and Form Variables
- It doesn’t show the real URL where it redirects the request in the users Web Browser
- Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another
What are the different types of Validation controls in ASP.NET?
In order to validate user input ASP.NET provides some validation controls. They are:
- RequiredFieldValidator -validates compulsory/required input.
- RangeValidator -validates the range.
- CompareValidator -validates or compares the input of a control with another control value or with a fixed value.
- RegularExpressionValidator -validates input value against a defined regular expression pattern.
- CustomValidator -allows to customize the validation logic with respect to our application logic.
- ValidationSummary -displays all errors on page collectively.
Differentiate between client-side and server-side validations in Web pages.
What are the types of Authentication in ASP.NET?
There are three types of authentication available in ASP.NET:
- Windows Authentication -It uses built-in windows security features to authenticate user.
- Forms Authentication -It authenticate against a customized list of users or users in a database.
- Passport Authentication: -It validates against Microsoft Passport service which is basically a centralized authentication service.
What are Session state modes in ASP.NET?
ASP.NET supports different session state modes:
- InProc Mode –It stores session state on the web server memory where the application is running. It is the default modes.
- StateServer Mode – It stores session state in a separate process called the ASP.NET state service. It is accessible from multiple web servers in a Web farm. It is available if the application is restarted.
- SQLServer Mode –It stores session state in a SQL Server database. It has the same advantages as like StateServer mode.
- Custom Mode –It allows us to define custom storage provider.
- Off Mode –it disables session state.
What is Query String? What are its advantages and limitations?
A query string is the portion of a URL where data is passed to a Web application. It helps in sending the page information to the server.
Advantages of Query String:
- Every browser works with Query Strings
- It does not require server resources and so no extra pressure on the server
Limitations of Query String:
- It does not support many character. So Information must be within the limit
- Information security is low. Because URL is visible to the user
What is Caching?
Caching is a technique used to keeping frequently accessed data or files in memory. It increases the performance. The request for a cached file/data will be accessed from cache instead of actual location of that file.
What are the different types of caching?
ASP.NET has 3 kinds of caching:
- Output Caching
- Fragment Caching
- Data Caching
What is the difference between page-level caching and fragment caching?
In the page-level caching entire Web page is cached. In the fragment caching, a part of the Web page, such as a user control added to the Web page, is cached.
How to cache different version of same page?
In ASP.NET we can cache multiple versions of the same page by using output caching. The output cashing has four attributes that enable us to cache multiple versions of same page.
It caches different version depending on input parameters (query string) send through HTTP POST/GET.
It caches different version depending on the contents of the page header.
It caches different version by browser type or by a custom string that we define.
It caches different versions of a user control based on the value of properties of ASP objects in the control.
For example consider the following codes:
<%@ OutputCache Duration="30" Location="Server" VaryByParam="state" VaryByCustom="minorversion" VaryByHeader="Accept-Language"%>
What is Protected Configuration?
It is a feature used to secure connection string information
What is the good practice to implement validations in aspx page?
Client-side validation is the best way to validate data of a web page. It reduces the network traffic and saves server resources.
Which protocol is used to call a Web service?
List the major built-in objects in ASP.NET?
What are the different types of cookies in ASP.NET?
- Session Cookie – Stay on the client machine for a single session until the user does not log out.
- Persistent Cookie – Stay on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.
What is the file extension of web service?
Web services have file extension .asmx..
What are the components of ADO.NET?
The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.
What is the difference between the Response.Write() and Response.Output.Write() methods?
The Response.Write() method allows us to write the normal output.
Response.Output.Write() method allows us to write the formatted output.
What is the default timeout for a Cookie?
The default time duration for a Cookie is 30 minutes. But it can change it.
What is tracing?
In ASP.NET tracing is an activity of recording the diagnostic information related to a specific web page that is being executed on the web server. Tracing is a great way to get information about pages without a lot of hassle.
Why we need tracing?
In the development stage, we can easily troubleshoot the application by using built in debuggers. But after deployment this is not possible. Microsoft .Net provides a mechanism to rack the execution flow of ASP pages easily. Tracing help us to view the HTTP request, session states easily. We can also save trace information into a custom log file.
What are the types of tracing?
In ASP.NET there two types of tracing:
- Application Level
- Page Level
What is application level tracing?
In Application Level tracing trace result is not displayed on the page that is executed. The result is stored on the web server, in the root folder of the application as a file. The file named is “trace.axd”. After execution of the pages, this file can be viewed on the browser. A sample example is: http://myApplication/trace.axd. To enable application level tracing, write the following code in web.config file.
<system.web> <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false"/> </system.web>
What is page level tracing?
In Page Level tracing trace result is displayed on the page that is executed. To enable page level cacing write the following code in the top of the page:
<%@ Page Language="C#" AutoEventWireup="False" Codebehind=" Default.aspx.cs " Inherits=" Default.aspx" Trace="True" %>