• Register
360 points
8 4 2

Want to solve programming problems and get paid for it? If that sounds interesting to you then contact us.

1.What is the ASP.NET Core?

ASP.NET Core is not an upgraded version of ASP.NET. ASP.NET Core is completely rewriting that work with .net Core framework. It is much faster, configurable, modular, scalable, extensible and cross-platform support. It can work with both .NET Core and .net framework via the .NET standard framework. It is best suitable for developing cloud-based such as web application, mobile application, IoT application.

 

2.What is Metapackages?

The framework .NET Core 2.0 introduced Metapackage that includes all the supported package by ASP.NET code with their dependencies into one package. It helps us to do fast development as we don't require to include the individual ASP.NET Core packages. The assembly Microsoft.AspNetCore.All is a meta package provide by ASP.NET core.

 

3.Why Use ASP.NET Core for Web Application Development?

ASP.NET Core is an robust, and feature-rich framework that provides features to develop super-fast APIs for web apps. ASP.NET Core should be prefered for following reason:

  • ASP.NET Core is faster compare to traditional ASP.NET.

  • Cross-platform: Runs on Windows, MacOS and Linux; can be ported to other OSes. The supported Operating Systems (OS), CPUs and application scenarios will grow over time, provided by Microsoft, other companies, and individuals.

  • Flexible deployment: Can be included in your app or installed side-by-side user or machine-wide. Runs on IIS or can be self-hosted in your own process.

  • Built-in support for dependency injection.

  • ASP.NET Core is cloud-ready and has improved support for cloud deployment.

  • Provides Support for Popular JavaScript Frameworks.

  • Unification Of Development Models which allows the MVC and Web API development models to use the same base class Controller.

  • Razor Pages makes coding page-focused scenarios easier and more productive.

  • Environment based configuration supported for cloud deployment.

  • Built in logging support.

  • In ASP.NET we had modules and handlers to deal with requests. In ASP.NET Core we have middleware which provides more control how the request should be processed as they are executed in the order in which they are added.

 

4.What is Startup.cs file in ASP.NET Core?

In ASP.NET, Global.asax (though optional) acts as the entry point for your application. Startup.cs, it is entry point for application itself. The Startup class configures the request pipeline that handles all requests made to the application. Read this read this excellent post The Startup.cs File in ASP.NET Core 1.0 – What Does It Do? to know more about startup.cs.

5.What are the new features the dot net core provides?

Below are new features provided by dot net core framework

 

  • Dot net core introduced a new webserver called “Kestrel” which can work on cross-platform, it means your web application can run on other platforms like Linux, Mac, etc.

  • It supports an in-build dependency injection, you do not need to install any third party DLL for it.

  • Now dot net core unified the MCV controller and Api controller.

  • It is an open-source. So the community can contribute.

  • Razor pages more code-focused

  • Side-by-side app versioning, It means If I have 2 applications A and B, A can target .NET Core 2.1 and B can target .NET Core 2.2.

  • It is lightweight and gives high performance.

  • You can host your application on IIS, Nginx, Docker, Apache, and self-Host.

  • Configure your appsettings.json based on the hosting environment.

  • Great support for the cloud.

 

6.What is Kestrel?

Kestrel is a fast, new cross-platform web server introduced in dot net core that can run your web application on Linux, macOS, etc.

 

You can set a kestrel server in the program.cs file

public static void Main(string[] args)

{

    var host = new WebHostBuilder()

        .UseContentRoot(Directory.GetCurrentDirectory())

        .UseKestrel()

        .UseIISIntegration()

        .UseStartup<Startup>()

        .ConfigureKestrel((context, options) =>

        {

            // Set properties and call methods on options

        })

        .Build();

    host.Run();

}


 

7.Dependency Injection in Dot net core.

The DotNet core has an In-build dependency mechanism. You have to add namespace Microsoft.Extensions.DependencyInjection in Startup.cs file to get enable IServiceCollection. In the ConfigureServices method, you can add your decencies to a container that will automatically resolve your dependencies and you can access your classes anywhere in the application. The built-in IoC container supports three kinds of lifetimes: 

 

  • Singleton: It creates and shares a single instance of service throughout the application's lifetime.

  • Transient: It creates a new instance of the specified service type every time when it requested. This lifetime works best for lightweight, stateless services.

  • Scoped: It creates an instance of the specified service type once per request and will be shared in a single request.

 

8.What is Middleware?

Middleware is a pipeline that handles requests and responses. Requests are passes through this pipeline where all middleware is configured and it performs an action before passing it to the next middleware. The following diagram shows the concept of middleware.

 

9.What is the difference between services.AddTransient and service.AddScope methods are Asp.Net Core?

ASP.NET Core out of the box supports dependency injection. These 3 methods allows to register the dependency. However, they offers different lifetime for registered service. Transient objects are created for every request (when requested). This lifetime works best for lightweight, stateless services. Scoped objects are the same within a request, but different across different requests. Singleton objects created the first time they’re requested (or when ConfigureServices is run and an instance is specified with the service registration).

 

10.What is routing in ASP.NET Core?

Routing is functionality that map incoming request to the route handler. The route can have values (extract them from URL) that used to process the request. Using the route, routing can find route handler based on URL. All the routes are registered when the application is started. There are two types of routing supported by ASP.NET Core

 

The conventional routing

 

Attribute routing

 

The Routing uses routes for map incoming request with route handler and Generate URL that used in response. Mostly, the application having a single collection of routes and this collection are used for the process the request. The RouteAsync method is used to map incoming request (that match the URL) with available in route collection.

 

11.What is ASP.NET Core Module (ANCM)?

ASP.NET Core Module (ANCM) lets you run ASP.NET Core applications behind IIS and it works only with Kestrel; it isn’t compatible with WebListener. ANCM is a native IIS module that hooks into the IIS pipeline and redirects traffic to the backend ASP.NET Core application. ASP.NET Core applications run in a process separate from the IIS worker process, ANCM also does process management. ANCM starts the process for the ASP.NET Core application when the first request comes in and restarts it when it crashes. In short, it sits in IIS and routes the request for ASP.NET Core application to Kestral.


 

12.Where static files contains in asp.net core application?

There is a folder called "wwwroot", under this folder has several folders where you can find the CSS, js files.

 

wwwroot

 

  • CSS

  • js

  • lib


 

13.What are the Razor Pages in Asp.net Core?

Razor Pages is a new feature of ASP.NET Core that makes coding page-focused scenarios easier and more productive. The Razor Pages are lightweight and very flexible for building dynamic, data-driven web sites with clean separation of concerns.

 

14.What does WebHost.CreateDefaultBuilder() do?

This method does the following things.

 

  • Configure the app to use Kestrel as web server.

  • Specify to use the current project directory as root directory for the application.

  • Setup the configuration sub-system to read setting from appsettings.json and appsettings.{env}.json to environment specific configuration.

  • Set Local user secrets storage only for the development environment.

  • Configure environment variables to allow for server-specific settings.

  • Configure command line arguments (if any).

  • Configure logging to read from the Logging section of the appsettings.json file and log to the Console and Debug window.

  • Configure integration with IIS

  • Configure the default service provider.


 

15.What is tag helper in ASP.NET Core?

It is a feature provided by Razor view engine that enables us to write server-side code to create and render the HTML element in view (Razor). The tag-helper is C# classes that used to generate the view by adding the HTML element. The functionality of tag helper is very similar to HTML helper of ASP.NET MVC.

 

 Example:

 //HTML Helper

 @Html.TextBoxFor(model => model.FirstName, new { @class = "form-control", placeholder = "Enter Your First Name" }) 

 

 //content with tag helper

 <input asp-for="FirstName" placeholder="Enter Your First Name" class="form-control" /> 

 

 //Equivalent HTML

 <input placeholder="Enter Your First Name" class="form-control" id="FirstName" name="FirstName" value="" type="text"> 


 

16.What are the new features that brought Dotnet core 2.2?

  • OpenAPI Analyzers & Convention

  • Problem details support

  • New Endpoint Routing

  • NET Core 2.2 adds support for HTTP/2

  • Options to configure Kestrel

  • NET Core 2.2 introduces a Java Client for SignalR

  • Performance of SocketsHttpHandler was improved by reducing connection pool locking contention.

  • Validation performance

360 points
8 4 2