ASP.NET is an Open-Source web framework for building fast, secure web apps & services with .Net. ASP.NET is also a cross-platform framework that has the biggest draw that means, which can run on any operating system so this allows you to build your ASP.NET web apps using HTML, CSS, Javascript, or Jquery. This Tutorial contains ASP.NET Interview Questions and Answers. ASP.NET training & asp.net interview question answer pdf allow you to build web API that can be consumed with any other third party resources like Microsoft, Facebook, or Google.
ASP.NET Framework is a part of the .NET framework used to create a dynamic website, web application, and web services. It is a server-side technology that uses all .NET compatible languages such as C#, VB.NET, J#, etc. which are compiled to Microsoft Intermediate Language (MSIL). ASP.NET uses server control to develop a rapid and interactive application easily.
Any ASP.Net applications would also be written in multiple choice of .Net languages that include C#, VB.Net, and J# and it provides multiple development modes, that help to develop an application in an easy and better way.
It uses C# and VB.NET languages to build the website.
It allows us to separate the HTML layout with server-side code.
It allows us to make the same class name qualifying under a different namespace.
ASP.NET pages are compiled, not interpreted.
There are the following differences between these two :
On a website, you cannot add multiple projects.
There is no project file (.csproj or .vbproj). All the files in a folder structure are automatically included on the site.
By default, compilation produces multiple assemblies.
The website is easy to create and deploy.
You can use different .NET languages on a single website such as VB.NET pages and C# pages can be used on a single website.
You can edit a single page/file after deployment recompilation is not required.
Choose a website where one developer will be responsible for creating and managing an entire website. Since decoupling is not possible on the website.
In a web application, you can add multiple projects.
It has a Visual Studio project file (.csproj or .vbproj) that stores information about the project like as the list of files that are included in the project, and any project-to-project references.
By default, compilation of code files (excluding .aspx and .ascx files) produces a single assembly.
It is easy to develop compared to the website.
You cannot use different .NET languages in a Web Application such as C# and VB.NET both cannot be used in a web application.
You cannot edit a single file. Recompilation is required.
The right choice for enterprise environments where multiple developers work for creating, testing, and deployment. Different groups work on various components independently as one group works on the domain layer, and other work on the UI layer hence, decoupling is possible here
The trip of a Web page from the client to the server and then back to the client is known as a round trip.In ASP.NET Response.Redirect() causes a round trip.
In other words, any web page that travels from the client side to the server side will get processed on the server and travels back to the client, this whole process is called a round trip.
Following are the important aspect of the use of the Global.asax file.
The code in the Global.asax is compiled when the web application is built for the first time.
Session-level code and variables can be declared in the Application_Start event.
Application-level events are for the entire application and may be used by any user.
Both files are used to define configurations for your ASP.NET application. There are the following differences between these two configuration files.
The Web. config is used to define application-level settings.
If any setting is not specified in Web.config it inherits from Machine.config by default.
Web.config is an XML-based configuration file for an ASP.NET application that includes the settings for Data Connection, Customizing Security, State Management, Memory Management, Error Handling, and much more.
It is sometimes called an application and session-level configuration file.
This file is at the highest level in the configuration hierarchy.
You can find it at \Microsoft.NET\Framework\\config\machine.config
Machine.config is used for defining server-level settings.
It defines the supported configuration file section and ASP.NET work process.
It registers providers that can be used for advanced features such as profile membership and role-based security.
It is automatically installed while installing Visual Studio.NET.
It is sometimes called a machine-level configuration file.
Following is the way to define a connection string in Web.config for SQL Server database.
PreInit: This is the first event of a page used to set values such as a master page.
Init: This event fires after each control have been initialized. You can use this event to change the initialized value of controls.
InitComplete: This event is raised after all initializations of a page and its controls have been completed.
PreLoad: This event fires before the view state has been loaded for a page and its controls and before page postback processing. This event is useful when you need to write code after the page is initialized.
Load(PageLoad): The page load event is generally used to check postback and then sets control properties appropriately. After this event, the load event of child control is called.
ControlEvents(Postback): This event is called when a page or its controls causes postback such as ButtonClick event, SelectedIndexChanged event, CheckedChanged events, etc.
LoadComplete: At this event, all controls are loaded even after additional processing can be done here.
PreRender: This event is taking place before the view state is saved also it allows final changes to the page or its control.
SaveStateComplete: Any changes to the page’s controls at this point are ignored here. This event is useful if you need to write processing that requires the view state to be set.
Render: In reality, it is not an event this is actually a method of a page object and its controls. At this point, controls are rendered in client-sideHTML, DHTML, and scripts for the browser.
The ASP.NET server controls are objects on the ASP.NET pages that run when the Web page is requested. Many server controls, such as buttons and text boxes, are similar to the HTML controls. In addition to the HTML controls, there are many controls, which include complex behavior, such as the controls used to connect to data sources and display data.
Hyperlink control does not have the Click and Command events; whereas the LinkButton control has these events, which can be handled in the code-behind file of the Web page.
Navigation controls help us to navigate in a Web application easily. These controls store all the links in a hierarchical or drop-down structure; thereby facilitating easy navigation in a Web application.
Client-side validations work at the client end with the help of scripting languages such as JavaScript or jQuery and VBScript. On the other hand, server-side validations work at the server end with the help of programming languages like C#, VB, F#, etc. Server validations work when you submit or send data to the server.
The differences between User Control and Custom Control are given below-
User Control Custom Control Built into .ascx file. Built into a redistributable assembly (i.e. a DLL). Generally used for static content. Generally used for dynamic content. It is easy to create and use as it inherits from server controls. Comparatively difficult because you have to develop from scratch. Can be only used with current applications. Can be used with any number of applications. Language dependent. Language independent, a control created in C# can be used in VB.NET. Cannot be added to the Visual Studio toolbox. Can be added to the Visual Studio toolbox.Identifying the culture and locale that must be supported by the application.
Designing features to support those cultures and locales.
Localization is the process of customizing your application for a given culture or locale. In other words, Localization is the process of customizing your application in such a way that it behaves as per your current culture or locale. Typically, Localization translates your application UI into the current culture or locale.
ASP.NET provides resource files to implement globalization and localization. The resource file is an XML file having extension resx. Each resource in the resx file is in the form of a key-value pair. For each culture that your application needs to support create a separate resource file. For example, WebResources.en.resx is a resource file for the English language, and WebResources.hi.resx is a resource file for the Hindi language.
There are two types of resource files as given below :
Local Resources: Local resources are specific to a single web page and are used for providing versions of a web page in different languages. These are stored in the App_LocalResources folder.
Global Resources: Global resources are common for the whole web application and can be accessed by all the web pages. These are stored in the App_GlobalResources folder.
A neutral culture is a culture that is associated with a language but not with a country or region. For example, "en" for English and in for Hindi. Culture consists of language and the country or region. It is denoted by culture code which contains two lowercase letters denoting the language and two uppercase letters denoting the country or region like as en-US for English in the US, en-GB for the UK, etc. A language is any spoken language like English (en), Hindi (hi), and German (de), etc.
For sorting, you need to handle the SortCommand event and rebind grid required and for paging, you need to handle the PageIndexChanged event and rebind grid required
Built-in supports for Update and Delete operations. Need to write code for implementing Update and Delete operations. Supports auto format or style features. This feature is not supported. Performance is slow as compared to DataGrid Performance is fast as compared to GridView.The differences between ListView and Repeater are given below :
ListView Repeater It was introduced with ASP.NET 3.5 It was introduced with ASP.NET 1.0 Built-in supports for paging and sorting. Need to write custom code. Built-in supports for Data grouping. Need to write custom code. Built-in supports for insert update and delete operation. Need to write custom code. Performance is slow as compared to Repeater Performance is fast as compared to ListViewThere are following the different modes of session states which can be defined in a Web.config file.
Off: Specify that Session state is not enabled.
InProc: This is the default mode of the session. In this mode session state is stored on the web server i.e. IIS where an application is running.
State Server: In this mode, the session is stored in a separate process called ASP.NET state service. This ensures that the session state will be available in the web application and is restarted. This way also makes the session state available to multiple web servers in a web farm.
Note: Session_End event of Global.asax is fired only in InProc session mode. The object stored in the Session state must be serializable if the session mode is set to OutProc.
The Model-View-Controller (MVC) represents an architectural pattern that splits an application into 3 key logical components. The names of these components are the model, the view, and the controller. Keep in mind that this pattern is not related to the layered pattern. Essentially, the MVC pattern runs on the software side.
In a particular application that implements the MVC pattern, every component comes with its role dedicated. To understand better, for example, model classes merely hold the data as well as the business logic. These classes don’t deal with the HTTP requests but they view only display information. Moreover, the controllers deal with and respond to user input and determine which model to be passed to which view. Doing this makes an application simple to develop and maintain as it expands in complexity.
NuGet is a package manager dedicated to the .NET ecosystem. Essentially, Microsoft developed it to offer access to thousands of packages being written by .NET developers. Also, you can use it for sharing the code you already wrote with others.
A classic web application being developed through ASP.NET depends on several open-source NuGet packages to work. One of the famous NuGet package managers is Newtonsoft.Json. It is used for working with JSON data in .NET.
Program.cs class signifies the entry point of our application. Any ASP.NET application begins identically as a console application, directly from a static void Main() function. It is this class that configures the web host which would serve the requests.
This class deals with two significant aspects of your application. They are service registration and middleware pipeline.
Two methods involved in startup class are ConfigureServices() and Configure().
Kestrel is an open-source type cross-platform web server uniquely designed for ASP.NET Core. It is incorporated and enabled by default in ASP.NET Core. Moreover, it can be utilized as a web server processing requests straight from a network.
The Kestrel is a cross-platform web server built for the ASP.NET Core based on "libuv" that is a cross-platform asynchronous I/O library which is a extremely fast library.
Dependency injection represents a design pattern that assists to develop loosely coupled code. It is this pattern that is widely used in ASP.NET. The purpose of using Dependency injection is to provide the objects with what they need in the particular object’s constructor instead of needing that object to construct them.
Dependency injection decreases and usually removes needless unnecessary dependencies between those objects that don’t require knowing one another. Also, it assists in testing by hitting out the dependencies at runtime.
For implementing dependency injection, we can try multiple paterrns such as constructor injection pattern or property injection patterns to make it work effectively.
RequiredFieldValidator: This validator is used when you don’t want the container to stay empty. It examines whether the control possesses any value or not.
RangeValidator: It finds out whether the value in validated control falls the specific range or not. CompareValidator: It tests if the value in controls matches certain specific values or not. RegularExpressionValidator: Tests if the particular value matches an explicit regular expression or not.
CustomValidator: Useful for defining User Defined validation.
Summary Validation:This shows a summary of all existing validation errors over an ASP.NET page.
State management is a method to manage a state of a particular object on various requests. The HTTP protocol is the elementary protocol of the World Wide Web. It is a stateless protocol which means that each request is generated from a new user in accordance with a web server. In any web application, maintaining the state is vital.
Above are the way to manage the state and all these are part of two categories which are given below.
Here is the brief of components of web forms in ASP.NET:
Server controls: They are Hypertext Markup Language (HTML) elements that contain a runat=server attribute. These components provide automatic state management as well as server-side events and react to the user events by implementing an event handler on the server. HTML controls: They also respond to the related user events but the events processing takes place on the client machine.
Data controls: Data controls enable connection to the database, run commands, and access data from a database.
System components: They offer access to system-level events that take place on the server.
In ASP.NET, the master pages, basically, creates a common structure, layout, elements which are usually shared among multiple content pages and provides a template on the basis of that structure for consistent layout and design on multiple pages in a web application.
ASP stands for Active Server Pages. It is a server side scripting language used to create dynamic and interactive web pages.
Authentication- It is the process in which the user's identity is verified who are accessing an ASP.NET application. It is done by validating their credentials like usernames and passwords. There are several kinds of authentication mechanisms in ASP.NET such as forms authentication, authentication with external identity providers like OAuth.
Authorization- It is the process of determining those actions which are allowed for authenticated users to perform within an ASP.NET application. It basically controls the access to resources depending upon what roles and permissions are assigned to the users
In ASP.NET MVC, Routing is a concept that refers to a mechanism which is used to define URL patterns for the application and then, those URL patterns are mapped onto specific controller actions. This routing system also does interpretation of the incoming URL requests and tells which controller and action is required to handle them.
In ASP.NET syntax, The role of the @ symbol is to denote different types of constructs and features. There are some common uses of the @ symbol that include:
In ASP.NET, the concept of partial views can be defined as the components that are reusable and are used to represent a part of a view or user interface. In simple words, it breaks down the complex view into its smaller components which makes it easier to manage them as they can be modified independently and reused across other views within the application as well.
ActionResult in ASP.NET is actually a base class for those classes who perform encapsulation of the result which is received by the execution of an action method. It has various derived classes representing different types of results. Some of them are:
In ASP.NET, session state are used to store and retrieve user specific data over many HTTP requests. The different types of session state modes are:
ViewState typically refers to a mechanism which is used in ASP.NET web forms to maintain the state of server-side controls across postbacks. Its main uses are to maintain these states across postbacks, to simplify development and state management. It also helps in improving user experience by retaining user input and control state.
In ASP.NET, the concept of bundling and minification refers to the techniques that help in optimizing the performance of web application by reducing the number of HTTP requests and minimizing the size of resourceslike CSS, JavaScript.
I hope these questions and answers will help you to crack your ASP.NET interview. These interview questions have been taken from our newly released eBook ASP.NET/AJAX Interview Questions & Answers. This book contains more than 110+ ASP.NET/AJAX interview questions.
This eBook has been written to make you confident in WCF with a solid foundation. Also, this will help you to turn your programming into your profession. It's would be equally helpful in your real projects or to crack your ASP.NET Interview.
Consider enrolling in our ASP.NET Core certification for a comprehensive step by step training.
You can prepare for ASP.NET interview with the help of resources like official Microsoft documentation, tutorials that you can get online for free and practice exercises on coding platforms.
Yes, you should definitely practice more and more coding exercises and get familiarized with algorithms and data structures.