Top 17 .NET Core Interview Questions

ASP.NET Core is the free & open-source framework developed by Microsoft. It is faster than ASP.NET. ASP.NET is cross-platform - supports Windows, Linux and Mac. ASP.NET Core works with both .NET Framework & .NET Core.

#1.

How does a .NET Core app start?

ASP.NET Core web application is basically a console application which starts executing from the entry point public static void Main() in Program class where we can create a host for the web application.

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

Let's see below steps to understand how a .NET Core or ASP.NET Core application starts:

  • ASP.NET Core applications require a WebHost, while non-web based apps require a GenericHost.
  • This host basically works as an umbrella for the .NET Core apps.
  • It sets up lot of app resources when an app starts such as:
    • It starts Kestrel Web Server
    • Loads configurations from various configuration providers
    • Setup logging
    • Setup Dependency injection (DI)
  • This host is created by CreateWebHostBuilder method.
  • CreateDefaultBuilder method initializes host with default settings, but you can override or add additional settings using available extention methods such as:
    • ConfigureAppConfiguration
    • ConfigureLogging
    • UseEnvironment
    • UseSetting
    • UseContentRoot
    • UseIISIntegration
    • UseStartup
  • Once host is setup, kestrel server is running, your app is ready to serve the web requests.

#2.

What is Host Builder?

A host builder is an instance of either HostBuilder orWebHostBuilder class.

  • For http-based workloads, we use WebHostBuilder
  • For non-http-based workloads, we use HostBuilder

For ASP.NET Core (HTTP Based workloads)

  • an instance of IWebHostBuilder can be received from CreateWebHostBuilder method
  • we can use this instance to add/modify/remove features from .NET Core host instance

#3.

Difference between .NET Core SDK and .NET Core runtime?

.NET Core runtime

A runtime is the set of components that must be installed on a machine to run a framework-dependent app on the machine.

The .NET Core runtime includes the CoreCLR and the .NET Core base class library (earlier known as CoreFX).

For example:

  • .NET runtime = CoreCLR + .NET Core BCL
  • ASP.NET Core Runtime = CoreCLR + .NET Core BCL + ASP.NET Core framework libraries

.NET Core SDK

The SDK includes everything you need to build and run .NET apps. It includes the following:

  • .NET Core run time (CoreCLR + .NET libraries )
  • .NET CLI
  • Language compiler
  • Other tooling

#4.

How would you host the .NET Core app on IIS?

To host an ASP.NET Core on IIS on Windows OS, you should download and install ASP.NET Core Hosting Bundle.

ASP.NET Core Hosting Bundle contains everything you need to run existing web/server apps. The bundle includes :

  • .NET Core runtime
  • ASP.NET Core runtime
  • ASP.NET Core IIS Module

ASP.NET Core IIS Module allows ASP.NET Core apps to run behind IIS.

#5.

Explain different ways to host a .NET Core Web Application?

#6.

IServiceProvider vs IServiceCollection

#7.

Difference between Configure and ConfigureServices methods. Which one is optional?

#8.

How to set the hosting environment in ASP.NET Core?

#9.

In-process hosting vs Out process hosting in .NET Core?

#10.

Explain usage of UseStaticFiles() and UseDefaultFiles() methods in .NET Core?

#11.

app.Use() vs app.Run() vs app.Map() vs vs app.MapWhen()

#12.

Difference between HTTP Handler and HTTP Modules?

#13.

How would you implement the HTTP Module in .NET Core?

#14.

How would you implement the HTTP Handler in .NET Core?

#15.

Name a few built-in HTTP Modules?

Here are a few built-in HTTP modules: - FormsAuthentication - SessionStateModules - HttpCacheModule

#16.

What is Configuration Provider in .NET Core?

#17.

Difference between AddScoped(), AddTransient() and AddSingleton() methods?