Top 50 ASP.Net Interview Questions and Answers in 2024

You are an ASP.NET programmer… Your next job interview is round the corner… You want to score that job… All that means is that you need to prepare well despite being knowledgeable in the domain. Generally, in technical job interviews, interviewers will not only ask complex questions, but you may also even face some very fundamental and rudimentary questions which can make or break the chance to win.

ASP.Net Interview Questions and Answers

You may need more than this set of questions to arm yourself fully for the interview. We recommend you to visit ASP .NET Tutorials and Courses, where you can find more reading material and get a full grip of ASP.NET.

Question: What is ASP.NET?

Answer: ASP.NET is an open-source server-side application framework designed for web developers to produce dynamic web pages with .NET framework. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services.

Question: What is ASP.NET MVC framework?

Answer: ASP.NET MVC is a web application framework for the .NET Platform used for building full stack web applications using the Model-View-Controller pattern.

Question: What is an ASP.NET Web API framework?

Answer: ASP.NET Web API is used purely for building backend web APIs which can be used by an array of clients, from the web to desktop to mobile. It forms the server component in the RESTful (Representational State Transfer) architecture.

Question: Which would be the right framework to be used ASP.NET MVC or ASP.NET Web API?

Answer: If one intends to build a server component that can be easily utilized by an array of clients then ASP.NET Web API is the way to go. If, however, the project is purely going to be used as a web application, then ASP.NET MVC is a more appropriate choice.

Question: What is the web.config file and what is used for?

Answer: The web.config file is crucial because it contains the configuration settings for the application. It keeps your entire configuration separate from your code so you can easily change settings without code changes. It also allows you to potentially encrypt the configuration settings for increased security.

Question: Which compiler is used in ASP.NET?

Answer: Roslyn is the name of the compiler used by .NET Framework.

Question: ASP.NET is open-source. Explain.

Answer: Microsoft is providing the full .NET server stack in open source which means it is a ‘free’ download. This includes ASP.NET, the .NET compiler, the .NET Core Runtime, Framework, and Libraries, enabling developers to build with .NET across Windows, Mac or Linux.

Question: Explain the request flow in ASP.NET MVC framework.

Answer: Request flow handles the request from the clients and passes it to the server. Request hits the controller coming from the client. Controller plays its role and decides which model to use in order to serve the request further, passing that model to view which then transforms the model and generates an appropriate response that is rendered to the client.

Question: Explain the various modes for the Session state in ASP.NET?

Answer: There are various modes for storing session state:

Question: Explain the differences between GridView and DataGrid?

Answer:

GridView DataGrid
In-built support for paging, sorting and in-place editing using PagerSettings property. Requires custom code for paging, sorting and editing.
Uses data source control's sorting, update, delete, and paging options. Only data selection is supported by default. Updates and deletions need custom code.
Supports additional column types like HyperLinkField, ButtonField etc. Supports only limited column types.
Supports both preoperative and postoperative events. Raises single events for operations.

Question: How would you explain the differences between ListView and Repeater?

Answer:

Repeater ListView
Flexible layout introduced in .NET 1.0. Flexible layout with easy customization introduced with .NET 3.5
No built-in support, custom code should be written for data grouping and paging. Provides built-in support for data grouping and paging.
Update, insert, delete and sorting operations are not supported. All the operations are supported.
Offers better performance. Slower performance compared to a repeater.

Question: Explain Local Resources and Global Resources?

Answer:

Local Resources Global Resources
A local resource can only be accessed by the page that created it. Accessible by all pages.
Difficult to maintain when the website has a lot of localized content as each page requires a resource file for each language. Only one file per language is required.
Stored in the App_LocalResources folder. Stored in the App_GlobalResources folder.

Question: Briefly Describe Globalization and Localization?

Answer: Globalization is the growth of business outside the national borders. It involves understanding the laws and regulations of various countries to build the business environment. Globalization includes internalization and localization.

Localization is a procedure where a product is made available for the local market by making it appealing for the local community. It includes local preferences, culture and regional aspects other than just the translation of web pages in the local language.

For a stable worldwide business, you need both globalization – through which you can increase the reach of your business and localization – where you can show customized content based on the local preferences and other aspects.

These help in effective target marketing and cohesive global strategy.

Question: How are User Control and Custom Control different?

Answer:

User Control Custom Control
Stored as .ascx extension. It is a .dll extension.
They have a visual interface. These controls don't have a visual interface.
Do not appear in the toolbox and does not have design support; loaded at runtime. Can be added to the toolbox and used in various applications without re-compilation.
If we need controls particular to a website, user control is a good option. Custom controls can be created to be used across various applications.

Question: Explain server controls in ASP.NET?

Answer: Server controls are the primary controls in ASP.NET and are categorized in the following groups:

Question: Explain various page events in ASP.NET?

Answer: The various page events in ASP.NET are:

Event Description
Page request This event happens before the lifecycle begins. Whenever a user requests a page, ASP.NET parses and compiles the page.
Start Properties like Request and response are set, and the Request type is determined through this event
Initialize This event sets each control's UniqueID property and applies the Master page to the page.
Rendering In this event, 'Render' method is called for each control. A text writer writes the output (view state) to OutputStream object of the page's Response property
Load control properties are loaded with information if page request is a postback,
Postback event handling If page request is a postback, an event handler is called through this event. Afterwards, the Validate method of all validator controls is called
Unload This event happens after the requested page is fully rendered and is ready to discontinue. All properties are unloaded, and cleanup is done.

Question: Define a connection string in Web.config file?

Answer: Connection string contains information about the data source and how to connect to it.

Connection string is added as follows:

Question: Explain the difference between Web.config and Machine.config file?

Answer:

web.config machine.config
Stores the configuration settings for a particular web application. Specifies the configuration settings for all the websites hosted on the web server.
Located in the application's root directory. Located in $WINDOWSDIR$\Microsoft.Net\Framework\Version\Config
Overrides the settings in machine.config file. It is a master file that provides default settings that can be overridden.

Question: Explain the Global.asax file?

Answer: It is an optional file and is also called as the application file for ASP.NET. It contains code that responds to session-level and application-level events raised by HTTP modules or ASP.NET.

Question: Briefly describe the difference between the Web Site and Web Application?

Answer:

Website Web Application
Contains static content available publicly to all the visitors. Dynamic and interactive content.
The content is readable by all but cannot be changed or manipulated. An end-user can read and manipulate the restricted data.
These are mostly informational websites hence authentication is not mandatory. Needs authentication as these have more features and options for the user.
It is simple to create as just information is loaded and updated. Since there is interaction with the end-user, web applications are complex and perform more functions.
Website is a whole product that is accessible through the browser. It is one part of the whole website. it cannot be accessed directly.
No pre-compilation is required, only HTML code needs to be refreshed. Pre-compilation is required before deployment.

Question: Explain View State? And its advantages and disadvantages.

Answer: Suppose a user submits a form and there are validation errors or if the page refreshes after the user enters a lot of information on the page. In such cases, the information already written by the user will be lost, and he/she has to fill everything again. To avoid this from happening, ASP.NET uses ViewState, which retains the values already entered by the user. It is a built-in state management technique to preserve the form data.

Advantages:

Disadvantages:

Question: Explain Cookies in ASP.NET?

Answer: A cookie is a part of text that stores user-specific data. Cookies are stored by the browser in a user's hard drive and used whenever the user requests for a particular page. Cookies help in improving user experience and loading pages faster based on the date and time information stored as part of the data. In ASP, cookies can be created as well as retrieved. There are two types of cookies in ASP – persist, non-persist.

Question: Explain the purpose of Web Services in ASP.NET?

Answer: ASP.NET can create web services which are nothing but programs that use XML to exchange data with other software programs through commonly used internet protocols. We can communicate with any object over the internet using web service.

Web services are language-independent, platform-independent, protocol-independent, self-describing and programmable.

Question: Explain App Domain Concept in ASP.NET with Example.

Answer: App domain or application domain in ASP.NET is a light-weight process that has its own set of code, configuration and data settings. It is a logical boundary that separates one application from accessing or interfering with others. App domains help in better utilization of resources by using fewer processes for executing different applications. For example, ASP.NET is a runtime host that creates different application domains for every user who accesses a web site. These can be created and set up for apps that need to isolate code or to load extensions dynamically.

Question: What is Query String in ASP? And what are its advantages and disadvantages?

Answer: A query string is a method of transporting data from page to page using the browser URL. It is attached to the URL using the question mark symbol (?). For example, http://xyz.com?userid=12334&pwd=rf5r5jm3smQ

Advantages: Easy to use, no server resources required, supported by all the browsers, contained in the HTTP request of the URL

Disadvantages: URL length cannot be greater than 255 characters; data is directly visible to everyone compromising the security.

Question: What is tracing in .NET?

Answer: Tracing in .net enables one to follow the execution path of a page, debug the application and display diagnostic information at runtime. Trace messages can be accessed and manipulated from the code allowing for finer control to add more details. The tracing data is organized into a set of tables by ASP.NET.

Question: Why do we use CheckBox in .NET?

Answer: The checkbox is used to get multiple inputs from the user. Users can select more than one choice from the given options. In the code, it is set as a yes/no or true/false option, when it is ticked, the value of the checkbox is true, else false.

Question: Explain the HTML server controls in ASP.NET?

Answer: HTML server controls provide automatic state and server-side event management. These are HTML elements that have the attribute runat=server. The HTML server control properties and output are the same as their equivalent HTML tags. These controls are compiled when the ASP.NET application is compiled.

Question: Briefly describe the application of state management in ASP.NET? Add Examples.

Answer: HTTP is stateless, i.e. doesn't remember the state of a user, for example, his previously visited websites, requests and URLs. However, for certain requests, we need to maintain the state of application until the end, and ASP.NET has two approaches for the same:

Question: Describe login Controls in ASP? Also, add source code and examples.

Answer: Login control provides a secure login solution with a user interface and properties for the customized display of text fields, messages and links for forgotten password and to other pages.

We can modify the existing LoginControl and select the format. Login control properties can be written in HTML as follows:

  



These can be set in CSS file too:
.LoginControl
<
background-color:#FFFFFF;
border-color:#CDCC99;
border-style:solid;
border-width:1px;
font-family:Times New Roman;
font-size:10px;
>

We can apply the CSS to the control using the CssClass attribute:

Question: What does “PostBack” mean in ASP.NET?

Answer: A PostBack happens when a user takes some action (like submitting a form) that sends information from the page to the server for processing via POST method.

Question: Explain the ASP.NET page life cycle in brief.

Answer: ASP.NET goes through a series of stages in the life cycle of each page.

Question: What is view state in ASP.NET?

Answer: View state is where data is used to preserve page values and control values of Web Forms during postback event handling. Data can be stored as hidden fields on the client web page.

Question: What is the difference between custom controls and user controls?

Answer: Custom controls are basically compiled code, i.e., DLLs. These can be easily added to the toolbox, so it can be easily used across multiple projects using a drag-and-drop approach. These controls are comparatively hard to create. But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but tightly coupled with respect to User Interface and code.

Question: What are the different Validators in ASP.NET?

Answer: ASP.NET validation controls define an important role in validating the user input data. Whenever the user gives input, it must always be validated before sending it across the various layers of an application. There are two types of validation in ASP.NET:

Client-Side Validation: When validation is done on the client browser, it is known as Client-Side Validation. You can use JavaScript to do the Client-Side Validation.

Server-Side Validation: When validation occurs on the server, then it is known as Server-Side Validation. Server-Side Validation is a secure form of validation. The main advantage of Server-Side Validation is if the user bypasses the Client-Side Validation, the problem can be caught on the server-side.

The following are the Validation Controls in ASP.NET:

Question: What does the method Finalize do in ASP.NET?

Answer: The Finalize method is used to perform cleanup operations on unmanaged resources held by an object. It puts an object in the finalization queue. The Object will then be collected by the garbage collector ready to be cleaned up.

Question: What is RedirectPermanent in ASP.Net?

Answer: RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns http 301 status code to the browser.

Question: What is the function of the LoginStatus Control?

Answer: LoginStatus control is used to display Login/Logout links based on the login/authorization status of the current user. If the user has successfully logged in, the Logout link will be displayed.

Question: What is a Repeater Control and what are the templates supported by the Repeater?

Answer: A Repeater is a Data-bound control. Data-bound controls are container controls. It creates a link between the Data Source and the presentation UI to display the data. The repeater control is used to display a repeated list of items. A Repeater has five inline templates to format it:

Question: What are the different Session state management options available in ASP.NET?

Answer: In-Process and Out-of-Process are the two session state management options.

Question: What is the difference Between Server.Transfer and Response.Redirect?

Answer: Server. Transfer sends information from one web request to another, all on the server side. A response is not sent to the browser. On the other hand, Response.Redirect sends an HTTP 302 message to the browser and causes a redirect in the browser.

Question: What is fragment caching?

Answer: Fragment caching refers to the caching of individual user controls within a Web Form. Each user control can have independent cache durations and implementations of how the caching behavior is to be applied. Fragment caching is useful when you need to cache only a subset of a page.

Question: What are web controls in ASP.NET?

Answer: Web controls are classes in the .NET framework. The controls have special tags understood by the server. They are created on the server and require a run at=”server” attribute to execute. They generate HTML code that is sent back to the browser.

Question: Give some examples of web controls.

Answer:

Question: What is a web service?

Answer: A Web service, in the context of .NET, is a component that resides on a Web server and provides information and services to other network applications using standard Web protocols such as HTTP and Simple Object Access Protocol (SOAP).

Question: What is the difference between session and application object?

Answer: The difference between session and application object is that all users share one Application object and with sessions, there is one session object for each user. Data stored in the application object can be shared by all the sessions of the application. Application object stores data in the key-value pair. Session object stores session-specific information and the information are visible within the session only. ASP.NET creates unique SessionId for each session of the application. SessionIDs are maintained either by an HTTP cookie or a modified URL, as set in the applications configuration settings. By default, SessionID values are stored in cookies.

Question: What is Caching and what are the benefits of using it?

Answer: Caching is a mechanism that improves performance for an application by storing data in the memory for faster access. When the application accesses data from Cache (i.e. in-memory) instead of fetching it from the original data store (maybe a database), it definitely improves performance. But Caching benefits are not limited only to performance; it also improves application Scalability and Availability.

Question: What are the types of Authentication in ASP.NET?

Answer: There are three types of authentication available in ASP.NET:

Question: What is ASP.NET AJAX?

Answer: Microsoft has provided an implementation of AJAX functionality known as ASP.NET AJAX. AJAX stands for Asynchronous JavaScript and XML. This is a cross-platform technology that speeds up response time and reduces traffic between client and server. ASP.NET AJAX is a set of extensions to ASP.NET and comes with reusable AJAX controls.

Question: What is the REST architecture?

Answer: REST (Representational State Transfer) is an architectural style for designing applications and it dictates to use HTTP for making calls for communications instead of complex mechanism like CORBA, RPC or SOAP. There are few principles associated with REST architectural style:

Question: ASP.NET is cross-platform Explain.

Answer: ASP.NET applications can be developed and run on any operating systems like Windows, Linux, macOS, and Docker. Hence it is called a Cross-platform framework.

Question: What is Razor in ASP.NET

Answer: Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. The server-based code can create dynamic web content on the fly, while a web page is written to the browser. When a web page is called, the server executes the server-based code inside the page before it returns the page to the browser. By running on the server, the code can perform complex tasks, like accessing databases. Razor is based on ASP.NET, and designed for creating web applications. It has the power of traditional ASP.NET markup, but it is easier to use and easier to learn.

Question: What is ASP.NET Core?

Answer: ASP.NET Core is the open-source and cross-platform version of ASP.NET. The Windows-only versions of ASP.NET, that existed before ASP.NET Core, is typically just referred to as ASP.NET.

Looking to brush up your ASP.NET before the interview? This best udemy course can be a great asset to you in preparing for your ASP.Net interview: The Complete ASP.NET MVC 5 Course.

Generic programming questions are inherent to any programming interview. Here is a great book with top coding and programming questions and answers: Cracking the Coding Interview: 189 Programming Questions and Solutions.

People are also reading: