Tech Point Fundamentals

Sunday, September 18, 2022

.Net Core Interview Questions and Answers - Part 03

ASP.Net Core Interview Questions and Answers - Part 03

AspDotNetCoreInterviewQuestionsAndAnswers

Are you preparing for the .Net Core Interview? If yes, then you are at the right place. This is the ASP.Net Core Interview Questions and Answers article series. Here we will see the Top 150+ .Net Core Interview Questions with Answers. 

Please visit our YouTube Channel for Interviews and other videos by below link:




Please read the complete Design Pattern, C#, MVC, WebAPI, and .Net Framework Interview Questions and Answers article series here.




Introduction


This is the 3rd part of the .Net Core Interview Questions and Answers article series. Each part contains ten .Net Core Interview Questions. Please read all the .Net Interview Questions list here.

I will highly recommend to please read the previous parts over here before continuing the current part:






ASP.Net Core Interview Questions and Answers - Part 03


Q023. What is ASP.NET Core? 

ASP.NET is a popular web-development framework for building web apps on the .NET platform. ASP.NET is a web application framework developed by Microsoft which was released as part of the .NET framework.  ASP.NET was the original ASP.NET implementation that ships with the .NET Framework, also known as ASP.NET 4.x.

ASP.NET Core is the open-source version of ASP.NET, that runs on macOS, Linux, and Windows. ASP.NET Core was first released in 2016 and is a re-design of earlier Windows-only versions of ASP.NET. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps.

ASP.NET Core is a brand new cross-platform web framework built with the .NET Core framework. It is not an update to the existing ASP.NET framework. It is a complete rewrite of the ASP.NET framework. It was built from scratch in the effort to make a modular, scalable, super-fast, configurable, cross-platform, and easily extended web framework.

Both the ASP.NET and ASP.NET Core run on C#, an object-oriented, general-purpose programming language. ASP.NET Core inherits many concepts and features from its ASP.NET heritage, but it’s fundamentally a new framework. 




Q024. What are the key features or characteristics of ASP.Net Core?

  1. Cross-Platform
  2. Open-Source
  3. High Performance
  4. Kestrel Web Server
  5. Inbuilt DI Container
  6. Fully async pipeline
  7. Much leaner and modular framework
  8. Cloud-ready environment
  9. Self Hosting and Multiple Hosting(Kestral, IIS, Nginx, Apache, Docker, HTTP.sys)




Q025. What is the difference between ASP.NET and ASP.NET Core?

  1. Asp.Net build for Windows while Asp.Net Core build for Windows, Mac, and Linux.
  2. Asp.Net runs on .Net Framework while Asp.Net Core runs on .Net Core and Full .Net Framework.
  3. Asp.Net supports WebForm, Asp.Net MVC, and Asp.Net WebAPI, while Asp.Net Core does not support WebForm. It supports MVC, Web API, and Asp.Net Web pages originally added in .Net Core 2.0.
  4. Asp.Net used only the IIS web server which is dependent on System.web.dll. On the other hand, Asp.Net Core is not dependent System.web.dll and so the IIS as well.
  5. ASP.Net support C#, VB, and many other languages and also support WCF, WPF, and WWF. On the other hand, ASP.Net support only C#, and F# language. VB support was added for a short time and no support for WCF, WPF, and WWF but support for WCF client libraries are available.
  6. Asp.Net MVC application added web.config, global.asax, ApplicationStart but Core did not support Web.config and Global.asax files. It is supporting appsettings.json.


  7. Container support is not suited for ASP.Net applications. But Container support is best suited for deployments like Docker.
  8. In ASP.Net we need to re-compile after the code change. But core browser refresh will compile and execute the code no need for re-compile again.
  9. Asp.Net has a good performance while ASP.Net core has a higher performance than ASP.Net 4x.
  10.  Windows technologies such as PowerShell are abandoned from ASP.NET Core 1.0. Instead, Microsoft heavily integrates Node.js which can be utilized to run pre and post-build events with Grunt or Gulp.

In a non-core framework, the MVC Controllers are inherited from the Controller class whereas the API controllers are inherited from the ApiController class. But with the Core framework, both types of controllers inherit from the same controller class.




Q026. What are the advantages of using ASP.NET Core over classic ASP.NET?

ASP.NET Core is a modular version of ASP.NET that combines ASP.NET MVC and the ASP.NET Web API. It runs on both the .NET Framework and .NET Core and is designed for building high-performance cloud and microservice apps; it is not intended as a replacement to ASP.NET in the .NET Framework.

Dot Net Core is the latest version of the ASP.Net framework and along with that ASP.Net Core is an open-source and cross-platform framework that gives you the privilege to develop modern web-based and windows based applications.



  1. Built-in dependency injection.
  2. A unified story for building Web UI and Web APIs.
  3. Razor Pages makes coding page-focused scenarios easier and more productive.
  4. Ability to develop and run on multiple Operating Systems like Windows, macOS, and Linux.
  5. Support for hosting Remote Procedure Call (RPC) services using gRPC.
  6. Side-by-side versioning.
  7. Ability to deploy on more than one server like IIS, Kestrel, Nginx, Docker, Apache, etc.
  8. Cloud-enabled framework, provide support for environment-based configuration systems.
  9. Lightweight, High performance, and modern HTTP request pipelines.
  10. Integration of many client-side frameworks like Angular and React.
  11. Blazor allows you to use C# code in the browser with JavaScript code.
  12. A well-suited architecture for testability.



Q027. When do you choose classic ASP.NET over ASP.NET Core?

ASP.NET 4.x is a mature framework that provides the services needed to build enterprise-grade, server-based web apps on Windows. ASP.NET is a better choice if you:

  1. Don’t need cross-platform support for your Web app.
  2. Need a stable environment to work in.
  3. Have nearer release schedules.
  4. Are already working on an existing app and extending its functionality.
  5. Already have an existing team with ASP.NET expertise
  6. If you want one version per machine
  7. If you want to develop using the VB language
  8. If you want to use the .Net Framework runtime






Q028. What is ASP.NET Core MVC?

ASP.NET Core MVC is a rich framework for building web apps and APIs using the Model-View-Controller design pattern. The ASP.NET Core MVC framework is a lightweight, open source, highly testable presentation framework optimized for use with ASP.NET Core.

ASP.NET Core MVC is a framework to build web applications and APIs. It's based on Model-View-Controller (MVC) Design Pattern. This design pattern separates an application into three main components known Model, View, and Controller. It also helps to achieve the SoC (Separation of Concern) design principle.






Q029. What is the ASP.NET Core application life cycle?

In ASP.NET MVC, a request is handled using HttpModules & HttpHandlers. But ASP.NET Core MVC request lifecycle involves middleware.

In ASP.Net Core all client's requests go to the web server (IIS/Apache/Nginx etc) and from the webserver to ASP.NET Core Server which is either Kestrel or another.

From here the request goes to the application middleware where requests are handled and responses are generated, and then this response is transferred to the client and vice versa to request.  



mvccore-lifecycle
Source: techbloginterview



Main() Method: When the application starts it hits the main() method inside the Program.cs file which includes all the required things of the lifecycle. The host is created first and then it is executed using the Run() method.

MainMethodOfStartUpClass



  1. The WebHostBuilder class is the helper class to create and configure a host for a web application.
  2. The UseKestrel() method is an extension method that specifies Kestrel as an internal web server. The Kestrel is an open-source, cross-platform web server for ASP.NET Core.
  3. The UseContentRoot() method specifies the current directory as a root directory which will be the src folder in the default ASP.NET Core project. The content root directory determines where the content files are located such as MVC view files, CSS, images, etc.
  4. The UseIISIntegration() method specifies the IIS as the external web server or the reverse proxy server.
  5. The UseStartup<startup>() method specifies the Startup class to be used by the web host. This Startup class is like global.asax of .NET framework where you can configure request pipeline (middleware).
  6. The app.Run() method starts the web application and blocks the calling thread till the host is shut down. The startup class can be configured using UseStartup<T>() method at the time of configuring the host in the Main() method of the Program class.



ConfigureServices(): 

The main method then calls the ConfigureServices method in the startup.cs.  This is where all the required services in the application are added. 

A ConfigureServices method is a place where you can register your dependent classes with the built-in IoC container. After registering the dependent class, it can be used anywhere in the application. You just need to include it in the parameter of the constructor of a class where you want to use it. The IoC container will inject it automatically.



Configure():

The ConfigureServices method then calls the configure method which calls the UseMvc middleware.

The Configure method is a place where you can configure the application request pipeline for your application using the IApplicationBuilder instance that is provided by the built-in IoC container. 

ASP.NET Core introduced the middleware components to define a request pipeline, which will be executed on every request. You include only those middleware components which are required by your application and thus increase the performance of your application.



Middleware:

MVC applications in .NET Core are built on top of a concept called middleware. Middleware components form the basic building block of the application’s HTTP pipeline, such as the ability to serve the files and route requests.

Routing Middleware:

The MVC middleware then calls the routing middleware (UseRouter).  MVC is actually implemented through this routing middleware component, which acts as sort of a gateway into the framework. 

A class called MVC Route Handler is used to handle incoming URLs that match a certain route template. These requests are then handed to the MVC framework.

When a request comes in, first, the attribute routes are evaluated, and then conventional routes. Attribute routing is handled by MVC AttributeRouteHandler. Attribute routes are evaluated in parallel while in conventional routing the sequence of routing specified matters.



MVC Route Handler:

MVC Route Handler begins the process of initializing and executing a Controller. Route data obtained from the incoming URL is converted into a concrete controller that can handle requests.

The MVCRouteHandler calls the RouteAsync method. This method calls the SelectCandidates method which selects all possible methods and checks if the entered URL has a match in the route data. 

Then the SelectBestCandidates method is called which narrows down the choice based on action constraints like HttpPost and HttpGet.If a match is found then the particular controller and action method are selected.



Controller Factory:

The MVC RouteHandler decides the controller that needs to be invoked. The controller Factory class and the controller activator class create an instance of the controller and an action method is selected. Controller Factory which is responsible for creating an instance of the controller class.

Before the controller is created, authorization filters are called. If the authorization is successful, then the controller is created. Once the controller is created and the action method selected, model binding takes place. This is responsible for populating the action method parameters using query strings, form data, route data, etc.

Controller Action Invoker:

Controller Action Invoker is a component that finds and selects an appropriate Action Method on that controller to process the request. Before the method is called Model Binding takes place, which maps additional data from our HTTP requests to parameters on our Action Methods.



Action Filter:

After the model binding takes place, the OnActionExecuting filter is executed. First, the action method is executed. Then, the OnActionExecuted filter is executed. Action Filters are also called before and after the method produces an Action Result.

Action Result:

After our Action Result has been prepared, the next stage triggers which is Result Execution. This action result is the base class for all action results in asp.net MVC. Depending on the result of an action method, it will return an instance of one of the classes that derive from the action result.

MVC separates declaring the result from executing the result. If the result is of type view, then View Engine will be called and is responsible for finding and rendering our view. 

If the result is not a view, the Action Result will usually execute and generate its own response. This result Execution is what finally generates the response to the original HTTP request that goes back to the Client.






Q030. Can ASP.Net Core work with the .NET framework? 

Yes. ASP.NET Core can work with the .NET framework using the .NET standard library. ASP.NET Core works with the .NET framework and this is officially supported by Microsoft.

One important benefit of using the Full .NET framework with Asp.Net Core is the availability of mature libraries and frameworks that are developed mainly to target the previous versions of the .NET framework.



Q031. Can ASP.Net Application run in Docker containers?

Yes, you can run an ASP.NET application or .NET Core application in Docker containers. But the .Net Core application is best suited for docker containers.




Q032. How many types of single-page application (SPA) templates are provided by the .Net Core?

Following SPA templates are available in the .Net Core:

  1. Angular
  2. React
  3. React with Redux
  4. JavaScript Services





To Be Continued Part-04...


Recommended Articles






Thanks for visiting this page. Please follow and join us on LinkedInFacebookTelegramQuoraYouTubeTwitterPinterestTumbler, and VK for regular updates.

    

1 comment:

Please do not enter any HTML. JavaScript or spam link in the comment box.