Change language

NET Core Interview Questions

ASP. NET Core is an open source cross-platform asp.net core training platform that runs on Windows, Linux and Mac to develop modern cloud-based applications, including IoT apps, web apps, mobile backends and more. It is the fastest web development framework from NodeJS, Java Servlet, raw performance PHP and Ruby on Rails. Prepare for the interview with the help of the ASP.NET Core Interview Question Pdf file and get a suitable development position in cloud-based application, including web app, IoT app, and mobile app.

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.

What are the features provided by ASP.NET Core?

Following are the core features that are provided by the ASP.NET Core

  • Built-in supports for Dependency Injection

  • Built-in supports for the logging framework and it can be extensible

  • Introduced new, fast and cross-platform web server - Kestrel. So, a web application can run without IIS, Apache, and Nginx.

  • Multiple hosting ways are supported

  • It supports modularity, so the developer needs to include the module required by the application. However, NET Core framework is also providing the meta package that includes the libraries

  • Command-line supports to create, build and run the application

  • There is no web.config file. We can store the custom configuration into an appsettings.json file

  • There is no Global.asax file. We can now register and use the services into startup class

  • It has good support for asynchronous programming

  • Support WebSocket and SignalR

  • Provide protection against CSRF (Cross-Site Request Forgery)

What are the advantages of ASP.NET Core over ASP.NET?

There are following advantages of ASP.NET Core over ASP.NET :

  • It is cross-platform, so it can be run on Windows, Linux, and Mac.

  • There is no dependency on framework installation because all the required dependencies are ship with our application

  • ASP.NET Core can handle more request than the ASP.NET

  • Multiple deployment options available withASP.NET Core

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.

Can ASP.NET Core application work with full .NET 4.x Framework?

Yes. ASP.NET core application works with full .NET framework via the .NET standard library.

What is the startup class in ASP.NET core?

Startup class is the entry point of the ASP.NET Core application. Every .NET Core application must have this class. This class contains the application configuration related items. It is not necessary that class name must Startup, it can be anything, we can configure startup class in Program class.

 
 public class Program
 {
 public static void Main(string[] args)
 {
 CreateWebHostBuilder(args).Build().Run();
 }
 
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .UseStartup<TestClass>();
 }

Describe the Dependency Injection

Dependency Injection is a Design Pattern that’s used as a technique to achieve the Inversion of Control (IoC) between the classes and their dependencies. ASP.NET Core comes with a built-in Dependency Injection framework that makes configured services available throughout the application. You can configure the services inside the ConfigureServices method as below.
services.AddScoped();
A Service can be resolved using constructor injection and DI framework is responsible for the instance of this service at run time. For more visit ASP.NET Core Dependency Injection

What is the use of ConfigureServices method of startup class?

This is an optional method of startup class. It can be used to configure the services that are used by the application. This method calls first when the application is requested for the first time. Using this method, we can add the services to the DI container, so services are available as a dependency in controller constructor.

public void ConfigureServices(IServiceCollection services)  
{
    services.Configure(Configuration.GetSubKey("AppSettings"));
    services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext();
    // Add MVC services to the services container.
    services.AddMvc();
}
The ConfigureServices method is optional and is defined inside the startup class as specified in the above code. It is called by the host before the Configure method to configure application services. The Configure method is used to add middleware components to the IApplicationBuilder instance available in the Configure method. The Configure method also defines how the application responds to the HTTP request and response. The Use extension method of an ApplicationBuilder instance is used to add one or more middleware components to the request pipeline. You can configure services and middleware components without the Startup class and its methods by defining this configuration inside the Program class in the CreateHostBuilder method.

What is ASP.NET Core Module (ANCM)?

Answer: The ASP.NET Core Module (ANCM) allows you to run ASP.NET Core applications behind IIS and works only with Kestrel; is not compatible with WebListener. ANCM is a native IIS module that plugs into the IIS pipeline and redirects traffic to the back-end ASP.NET Core application. ASP.NET Core applications run in a separate process from the IIS worker process. ANCM also manages processes. ANCM starts the process for the ASP.NET Core application when the first request arrives and restarts it when it fails. In short, it sits in IIS and routes the ASP.NET Core application request to Kestral.

What is the use of the Configure method of startup class?

It defines how the application will respond to each HTTP request. We can configure the request pipeline by configuring the middleware. It accepts IApplicationBuilder as a parameter and also it has two optional parameters: IHostingEnvironment and ILoggerFactory. Using this method, we can configure built-in middleware such as routing, authentication, session, etc. as well as third-party middleware.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();
  
    app.UseApplicationInsightsRequestTelemetry();
  
    if (env.IsDevelopment())
    {
        app.UseBrowserLink();
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
  
        // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
        try
        {
            using (var serviceScope = app.ApplicationServices.GetRequiredService()
                .CreateScope())
            {
                serviceScope.ServiceProvider.GetService()
                        .Database.Migrate();
            }
        }
        catch { }
    }
  
    app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
    app.UseStaticFiles();
    app.UseIdentity();
  
    // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
  
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

What is WebListener?

Answer: ASP.NET Core provides two server implementations Kestral and WebListener. WebListener is also a web server for ASP.NET Core that works only on Windows. It is based on the Http.Sys kernel mode driver. WebListener is an alternative to Kestrel that can be used to connect directly to the Internet without relying on IIS as a reverse proxy server.

What is a web application?

A web application is software that users can access through a web browser such as Chrome or Firefox. The browser makes an HTTP request to the web application for a specific URL. The web application server intercepts the request and processes it to generate a dynamic HTML response that is sent to the user. Some examples of popular web applications are StackOverflow, Reddit, Google, etc. A web application is different from a typical website. A website is static. When you visit the website, an HTML page is returned with no processing performed to create the content for that HTML page. You will see the same page when you reload the browser. In contrast, a web application can return a different answer each time it is visited. For example, let’s say you have a question about Stack Overflow. When you call up the URL, you will initially only see your question. However, if someone else answers your question, the browser will display that answer at the same URL the next time they visit. A web application consists of several independent layers. The typical example is a three-tier architecture made up of presentation, business, and data layers. For example, the browser (presentation) talks to the application server, which communicates with the database server to get the requested data. The following figure illustrates a typical web application architecture with standard components grouped according to different areas of interest. NET interview questions

What’s new in .NET Core 2.1 and ASP.NET Core 2.1?

Ans: .NET Core 2.1 and ASP.NET Core 2.1 bring many new features to the table. Read New Features in .NET Core 2.1 to learn more about .NET Core 2.1. Where, ASP.NET Core 2.1 introduces support for SignalR, HTTPS by default, introduction of HttpClientFactory and many others. Read a brief summary of what’s new in ASP.NET Core 2.1. Also read the migration guide for migrating the ASP.NET Core 2.0 application to 2.1.

What is middleware?

It is software which is injected into the application pipeline to handle request and responses. They are just like chained to each other and form as a pipeline. The incoming requests are passes through this pipeline where all middleware is configured, and middleware can perform some action on the request before passes it to the next middleware. Same as for the responses, they are also passing through the middleware but in reverse order.

middleware example

What is the difference between IApplicationBuilder.Use() and IApplicationBuilder.Run()?

We can use both the methods in Configure methods of startup class. Both are used to add middleware delegate to the application request pipeline. The middleware adds using IApplicationBuilder.Use may call the next middleware in the pipeline whereas the middleware adds using IApplicationBuilder.Run method never calls the subsequent ore next middleware. After IApplicationBuilder.Run method, system stop adding middleware in request pipeline.

What is the use of "Map" extension while adding middleware to ASP.NET Core pipeline?

It is used for branching the pipeline. It branches the ASP.NET Core pipeline based on request path matching. If request path starts with the given path, middleware on to that branch will execute.

 
 public void Configure(IApplicationBuilder app)
 {
 app.Map("/path1", Middleware1);
 app.Map("/path2", Middleware2);
 }

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.

How to enable Session in ASP.NET Core?

The middleware for the session is provided by the package Microsoft.AspNetCore.Session. To use the session in ASP.NET Core application, we need to add this package to csproj file and add the Session middleware to ASP.NET Core request pipeline.

 
 public class Startup
 {
 public void ConfigureServices(IServiceCollection services)
 {
 ….
 ….
 services.AddSession();
 services.AddMvc();
 }
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
 ….
 ….
 app.UseSession();
 ….
 ….
 }
 }

What is Entity Framework?

Most applications require data to be stored and retrieved. We usually store this data in a database. Working with databases can often be quite complicated. You need to manage database connections, convert data from your application to a format the database can understand, and solve many other subtle problems. The .NET ecosystem has libraries that you can use for this, such as: B. ADO.NET. However, it can still be complicated to manually build SQL queries and convert the data back and forth from the database to C # classes. EF stands for Entity Framework and is a library that offers an object-oriented way of accessing a database. It acts as an object-relational mapper, communicates with the database and assigns database responses to .NET classes and objects.

What are the various JSON files available in ASP.NET Core?

There are following JSON files in ASP.NET Core :

  • global.json

  • launchsettings.json

  • appsettings.json

  • bundleconfig.json

  • bower.json

  • package.json

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"> 

How to disable Tag Helper at element level?

We can disable Tag Helper at element level using the opt-out character ("!"). This character must apply opening and closing the Html tag.

Example
 <!span asp-validation-for="phone" class="divPhone"></!span>

What are Razor Pages in ASP.NET Core?

This is a new feature introduced in ASP.NET Core 2.0. It follows a page-centric development model just like ASP.NET web forms. It supports all the feature of ASP.NET Core.

Example
 @page 
 <h1> Hello, Book Reader!</h1> 
 <h2> This is Razor Pages </h2>

The Razor pages start with the @page directive. This directive handle request directly without passing through the controller. The Razor pages may have code behind file, but it is not really code-behind file. It is class inherited from PageModel class.

How can we do automatic model binding in Razor pages?

The Razor pages provide the option to bind property automatically when posted the data using BindProperty attribute. By default, it only binds the properties only with non-GET verbs. we need to set SupportsGet property to true to bind a property on getting request.

Example
 public class Test1Model : PageModel
 {
 [BindProperty]
 public string Name { get; set; }
 }

How can we inject the service dependency into the controller?

There are three easy steps to add custom service as a dependency on the controller.

Step 1: Create the service

 public interface IHelloWorldService
 {
 string SaysHello();
 }
 
 public class HelloWorldService: IHelloWorldService
 {
 public string SaysHello()
 {
 return "Hello ";
 }
 }

Step 2: Add this service to Service container (service can either added by singleton, transient or scoped)

 public void ConfigureServices(IServiceCollection services)
 {
 ….
 …
 services.AddTransient<IHelloWorldService, HelloWorldService>();
 …
 …
 }

Step 3: Use this service as a dependency in the controller

 public class HomeController: Controller
 {
 IHelloWorldService _helloWorldService;
 public HomeController(IHelloWorldService helloWorldService)
 {
 _helloWorldService = helloWorldService;
 }
 }

How to specify service lifetime for register service that added as a dependency?

ASP.NET Core allows us to specify the lifetime for registered services. The service instance gets disposed of automatically based on a specified lifetime. So, we do not care about the cleaning these dependencies, it will take care by ASP.NET Core framework. There is three type of lifetimes.

Singleton

ASP.NET Core will create and share a single instance of the service through the application life. The service can be added as a singleton using AddSingleton method of IServiceCollection. ASP.NET Core creates service instance at the time of registration and subsequence request use this service instance. Here, we do not require to implement Singleton design pattern and single instance maintained by the ASP.NET Core itself.

Example
 services.AddSingleton<IHelloWorldService, HelloWorldService>();

Transient

ASP.NET Core will create and share an instance of the service every time to the application when we ask for it. The service can be added as Transient using AddTransient method of IServiceCollection. This lifetime can be used in stateless service. It is a way to add lightweight service.

Example
 services.AddTransient<IHelloWorldService, HelloWorldService>();

Scoped

ASP.NET Core will create and share an instance of the service per request to the application. It means that a single instance of service available per request. It will create a new instance in the new request. The service can be added as scoped using an AddScoped method of IServiceCollection. We need to take care while, service registered via Scoped in middleware and inject the service in the Invoke or InvokeAsync methods. If we inject dependency via the constructor, it behaves like singleton object.

services.AddScoped<IHelloWorldService, HelloWorldService>();
Explain how conventional routing works? As the name suggests, conventional routing uses predefined conventions to match the incoming HTTP request to a controller’s action method. It handles the most general cases that a typical web application needs, but you can modify it to suit your specific needs. For example, the Configure() method in the Startup.cs class contains the following code that sets up the conventional routing.
app.UseEndpoints(endpoints =>
{
  endpoints.MapControllerRoute(
      name: "default",
      pattern: "{controller=Home}/{action=Index}/{id?}");
});
This code creates a single route named default. The route template pattern {controller=Home}/{action=Index}/{id?} is used to match an incoming URL such as /Posts/Archived/5 to the Archived(int id) action method on the PostsController, passing 5 for the id parameter. By default, the router uses the Index method on the HomeController.

ASP.NET Interview Questions

ASP.NET is a web application framework developed by Microsoft that was released as part of the .NET framework. Facilitates the creation of dynamic web applications. Some other examples of similar web application frameworks are Ruby on Rails (Ruby), Django (Python), and Express (JavaScript). ASP.NET Core is an open source, high-performance, cross-platform web application framework. Microsoft released the first version of ASP.NET Core in 2016. It enables developers to create modern cloud-ready applications. Cross-platform: The main advantage of ASP.NET Core is that it is not tied to a Windows operating system like the legacy ASP.NET framework. You can develop and run production-ready ASP.NET Core applications on Linux or Mac. High Performance - It was designed from the ground up to keep an eye on performance. It is one of the fastest web application frameworks out there today. Open Source - It is open source, after all, and thousands of developers around the world are actively contributing. Both ASP.NET and ASP.NET Core run in C #, a universal object-oriented programming language. ASP.NET Core inherits many of the concepts and features from its ASP.NET heritage, but it is essentially a new framework. Although Microsoft will support the legacy ASP.NET framework, it will not actively develop it further. The new ASP.NET Core framework will contain all the new features and enhancements. In the future, Microsoft recommends that developers build all new web applications using ASP.NET Core instead of the legacy ASP.NET framework. In this article, we will focus on the ASP.NET and ASP.NET Core interview questions. To limit the scope of the article, suppose you have programmed in the C # programming language. A basic understanding of common object-oriented concepts and front-end technologies such as HTML, CSS, and JavaScript is also expected. We have divided the interview questions into two sections. The basic interview questions cover the basics and focus on understanding the application structure of a basic ASP.NET project. Then we cover more advanced concepts like dependency injection, routing, and model binding in the advanced interview questions.

Summary

The pedagogy of learning has evolved with the advent of technology over the years. Basic ASP.NET training will help you understand this technology better. Through the training session, you will know that ASP.NET Core is not an enhanced version of ASP.NET. ASP. NET Core completely rewrites the work with the .NET Framework. It is a much faster, modular, configurable, scalable, cross-platform, and extensible support of the .NET world that companies from different parts of the world are adopting this technology for at a faster rate. You can even work with .NET Core and .NET Framework using the .NET standard framework. We hope these questions and answers help you identify your ASP.NET Core interview. These interview questions are excerpts from our new e-book ASP.NET Core Interview Questions & Answers. This book contains over 140 ASP.NET Core interview questions. This book was written with the intention of getting you ready for the ASP.NET Core interview with a solid foundation in ASP.NET Core in no time. It would be equally useful in your real world projects or for deciphering your ASP.NET Core interview.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically