Sindhuja Hari | 16 Nov, 2023

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:

  • InProc: The session state is stored in the memory on the web server. This is the default mode.
  • Custom mode: you can specify a custom storage provider.
  • Off mode: disables the session state.
  • OutProc: There are two ways to handle this mode:
  • StateServer: The session state is stored in a separate process known as ASP.net state service. The session state is retained even if the application server is restarted and is available to multiple Web servers.
  • SQLServer: Session state is stored in a database, thereby preserving the session state even if the Web application is restarted. Session state can be accessed by multiple Web servers in a Web farm.

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:

  • Validation controls:  These controls validate user input by running the client-side script
  • Data source controls:  These are used to provide data binding for multiple data sources.
  • Data view controls:  These controls are used to view/display list and table data that is obtained from data sources
  • Login and security controls:  used for user authentication
  • Master pages:  used for giving a consistent interface and layout for the whole application
  • Rich controls:  These are used to implement special features like fileupload, calendar control, AdRotator etc.
  • Navigation controls:   help in navigation through menus, tree views and so on
  • Personalization controls:   used for personalization of page based on user information and preferences

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:

<configuration>  
 <connectionStrings>  
   <add name="myConnection" connectionString="server=localhost;database=mydatabase;" />
 </connectionStrings>
</configuration>

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:

  • Ensures security as data is stored in an encrypted format.
  • No server resources used.
  • ViewState properties can be easily enabled or disabled.
  • Developers can develop it at page level or control level as per need.

Disadvantages:

  • If a huge amount of data is stored, loading the page may take longer than required.
  • Data doesn't transfer from one page to another (between pages).

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: 

  • Client-side state management: in this approach, the state information is directly stored on the client machine. Whenever there is a user request, the required information travels back and forth to cater to Request and response—for example, cookies, query string.
  • Server-side state management: in this method, the state information is stored in user memory. There are more secure domains at the server-side compared to client-side. Application state and session state come under server-side state management including In-Proc, State server and SQL server.

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:

<form id="form1" runat="server">  
<div>  
<asp:Login ID="Login1" runat="server" BackColor="#FFFFFF" BorderColor="#CDCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Times New Roman" Font-Size="10pt">  
<TitleTextStyle BackColor="#6B6B6B" Font-Bold="True" ForeColor="#E9967A" />  
</asp:Login>  
</div>  
</form> 
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:

<asp:Login ID="Login1" runat="server" CssClass="LoginControl">  

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.

  • Page request. The user requests a page. ASP.NET decides whether to compile it or serve it from a cache.
  • Page Start. The Request and Response objects are created.
  • Page Initialization. All page controls are initialized, and any themes are applied.
  • Page Load. ASP.NET uses the view state and control state properties to set the control properties. Default values are set in the controls.
  • Postback event handling. This event is triggered if the same page is loaded again.
  • Rendering. ASP.NET saves the view state for the page and writes the output of rendering to the output stream. It happens just before the complete web page is sent to the user.
  • Unload. The rendered page gets sent to the client. ASP.NET unloads page properties and performs cleanup. All unwanted objects are removed from memory.

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
  • Server-Side Validation

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:

  • RequiredFieldValidator Control
  • CompareValidator Control
  • RangeValidator Control
  • RegularExpressionValidator Control
  • CustomFieldValidator Control
  • ValidationSummary

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:

  • Displays Header text for a Data Source collection and applies a different style for the Header text.
  • Changes the background color or style of alternating items in a Data Source collection.
  • It defines how each item is rendered from the Data Source collection.
  • It will determine the separator element that separates each item in the item collection. It could be a
    or

    HTML element.
  • Displays a footer element for the Data Source collection.

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.

  • In-Process stores the session in memory on the web server.
  • Out-of-Process Session state management stores data in an external server. All objects stored in session are required to be serializable.

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:

  • Button
  • Calendar
  • Checkboxlist
  • DropDownList
  • RadioButtonList

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:

  • Windows Authentication: This authentication method uses built-in Windows security features to authenticate a user.
  • Forms Authentication: Authenticates against a customized list of users or users in a database.
  • Passport Authentication: Validates against Microsoft Passport service which is basically a centralized authentication service.

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:

  • Everything is a resource i.e. File, Images, Video, WebPage etc.
  • Every Resource is identified by a Unique Identifier.
  • Use simple and Uniform Interfaces.
  • Everything is done via representation (sending requests from a client to server and receiving responses from server to client).
  • Be Stateless- Every request should be an independent request.

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.

Here you can download ASP.net Interviews Questions PDF.

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:

By Sindhuja Hari

Sindhuja Hari, a technology geek, content producer & writer brings over 20 years of experience. She builds and delivers best in class content for global audiences. Her favorite domains/ genres are IT, Manufacturing, Logistics & Supply Chain, and Travel & Leisure.

View all post by the author

Subscribe to our Newsletter for Articles, News, & Jobs.

I accept the Terms and Conditions.

Disclosure: Hackr.io is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

In this article

Learn More

Please login to leave comments