Core Interview Question Part 2

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.

What Configure Services() method does in Startup.cs?

This method is optional. It is the place to add services required by the application. For example, if you wish to use Entity Framework in your application then you can add in this method.

public void ConfigureServices(IServiceCollection services)  
    // Add MVC services to the services container.

What Configure() method does in Startup.cs?

The Configure method is used to specify how the ASP.NET application will respond to HTTP requests. The request pipeline is configured by adding middleware components to an IApplication Builder instance that is provided by dependency injection. There are some built-in middleware’s for error handling, authentication, routing, session and diagnostic purpose. Highlighted lines in below code, are built-in Middleware with ASP.NET Core 1.0.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    if (env.IsDevelopment())
        // For more details on creating database during deployment see
            using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
        catch { }
    app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
    // To configure external authentication please see
    app.UseMvc(routes =>
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
} Core Interview Question

What is the difference between services. Add Transient and service.Add Scope 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 Configure Services is run and an instance is specified with the service registration).

What is Kestrel?

Kestrel is a cross-platform web server for ASP.NET Core based on libuv, a cross-platform asynchronous I/O library. Kestrel is the web server that is included by default in ASP.NET Core new project templates. If your application accepts requests only from an internal network, you can use Kestrel by itself.

If you expose your application to the Internet, you must use IIS, Nginx, or Apache as a reverse proxy server. A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel after some preliminary handling. The most important reason for using a reverse proxy for edge deployments (exposed to traffic from the Internet) is security. Kestrel is relatively new and does not yet have a full complement of defenses against attacks.

What is Web Listener?

ASP.NET Core ships two server implementations Kestral and Web Listener. Web Listener is also a web server for ASP.NET Core that runs only on Windows. It’s built on the Http.Sys kernel mode driver. Web Listener is an alternative to Kestrel that can be used for direct connection to the Internet without relying on IIS as a reverse proxy server.

Advance Core Interview Question

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 Web Listener. 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.

What does Web Host. Create Default Builder() 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.

What is the role of IHosting Environment interface in ASP.NET Core?

ASP.NET Core offers an interface named IHostingEnvironment, allows you to programmatically retrieve the current environment so you can have an environment-specific behavior. By default, ASP.NET Core has 3 environments Development, Staging, and Production. Previously, the developers have to build the application differently for each environment (Staging, UAT, Production) due to dependency on config file sections and the preprocessor directive applicable at compile time. ASP.NET Core takes a different approach and uses IHostingEnvironment to retrieve the current environment. You can also define a custom environment like QA or UAT. Core Interview Question

What is the use of UseIISIntegration?

This tells ASP.NET that IIS will be working as a reverse proxy in front of Kestrel. As if you expose your application to the Internet, you must use IIS, Nginx, or Apache as a reverse proxy server. When you wish to deploy your ASP.NET Core application on windows, you need to tell ASP.NET Core Host to use IIS integration.
Use Kestrel and UseIISIntegration must be used in conjunction as Use Kestrel creates the web server and hosts the code. UseIISIntegration specifies IIS as the reverse proxy server.

var host = new WebHostBuilder()

Note that code making call to UseIISIntegration() does not affect code portability.

What are the different ways for bundling and minification in ASP.NET Core?

There are different ways for doing bundling and minification in ASP.NET Core.

Gulp – was the default choice for ASP.NET Core till beta versions. Later it was removed due to performance and speed issue and replaced with BundlerMinifier. Read this post to find out the reasons of this decision.
BundlerMinifier – is a Visual Studio extension and it’s default choice now. You should see bundleconfig.json file in your default template. Read this post to know more about bundling and minification in ASP.NET Core.
ASP.NET Core Web Optimizer – ASP.NET Core middleware for bundling and minification of CSS and JavaScript files at runtime.
Grunt – can also be used with ASP.NET Core.

What is www root folder in ASP.NET Core?

In ASP.NET Core, all the static resources, such as CSS, JavaScript, and image files are kept under the wwwroot folder (default). You can also change the name of this folder.

Advance Core Interview Question

What is “Razor pages” in ASP.NET Core?

“Razor Pages” is a new feature of ASP.NET Core and it was released with ASP.NET Core 2.0 release. Razor Pages are simple pages or views without controllers and introduced with the intent of creating page focused scenarios where there is no real logic is involved. You will find razor pages similar to ASP.NET Web Forms. They work on the convention and need to be placed in Pages folder and the extension is .cshtml. Razor pages uses handler methods to deal with incoming HTTP request. Read this post to find out more about handler methods.

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

.NET Core 2.1 and ASP.NET Core 2.1 brings lots of new features on the table. Read New features of .NET Core 2.1 to know more about .NET Core 2.1. Where, ASP.NET Core 2.1 introduces supports for Signal R, HTTPS by default, introduction of Http Client Factory and many other.

What functionalities are supported by ASP.NET Core?

Built-in support for dependency injection
Built-in support for an extensible logging framework
Contains Kestrel – a cross-platform web server that allows web applications to execute without the need for IIS, Apache or Nginx.
Functionality to use multiple hosts
Supports modularity – the developer must include the module that is required by the application.
Makes use of an app JSON file to store settings instead of a web.config
Contains a startup class to initiate and run services (Instead of global. asax)
Has extensive support for asynchronous programming Core Interview Question

What is ASP.NET Core Middleware?

ASP.NET Core Middleware is a group of small modules that are incorporated into an HTTP request pipeline. Middleware is used to implement several tasks when handling requests. Such examples include authentication, session state retrieval and persistence, logging and much more. It gives you control on the order of when the requests should be executed, unlike ASP.NET Core HTTP modules.

Middleware is configured by code rather than web.config in ASP.NET. It is found inside your Startup.cs file:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 
     if (env.IsDevelopment()) 
     app.UseEndpoints(endpoints => 

The configure method as seen above is used to create a request pipeline via middleware’s. The method applies the following functionality:

Adds error pages and error handlers
Adds HTTPS Redirection
Adds support for static files
Makes use of ASP.NET Identity authentication
Adds routing and endpoint using map controllers

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

ASP.NET Core is a total rewrite of ASP.NET. It is an open-source cross-platform that allows you to build web applications in Windows, Mac and Linux. It is also capable of working with both .NET Core and .NET Framework.

Here are the main differences:

Project configuration – ASP.NET Core does not make use of web.config. Instead, appsettings.json or other custom configuration files are used. A new folder named www root is also added to the project structure. This is the container for all static files which are sent to the browser such as CSS, HTML, JavaScript and image files.
Not dependent on IIS – It is not IIS dependent like ASP.NET and allows you to host on IIS, Docker, Nginx, Kestral and Apache.
Installation – since its cross-platform, frameworks are prepackaged and compiled via NuGet.
Microservices – Microservices were simplified in .NET Core. Programmers can develop custom microservices and combine them to build powerful systems seamlessly.

Can ASP.NET Core work with .NET Framework?

Yes. ASP.NET Core can work with .NET framework using the .NET standard library.

Advance Core Interview Question

What’s the difference between .NET Core .NET Framework and .NET Standard?

.NET Standard is a specification for implementing the Base Class Library (BCL). BCL contains classes such as exception handling, XML, collections, I/O and networking. WPF, WCF and ASP.NET do not form part of BCL and so are not included in .NET Standard library.

NET Core is a managed framework that builds desktop and web applications in cross-platform.
.NET Framework is a framework that builds desktop and web applications in Windows only. It is highly dependent on the architecture.
Both “.NET Core” and “.NET Framework” include .NET Standard for BCL in their managed framework.

How do you enable a session in ASP.NET Core?

The package Microsoft.AspNetCore.Session provides the middleware for the session. To make use of this session in an ASP.NET Core application, you need to include this package in its csproj file. The Session middleware must then be added in the Startup file in the ASP.NET Core request pipeline.

public class Startup
   public void ConfigureServices(IServiceCollection services)

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)

What is Web Listener?

Web Listener is a web server in ASP.NET Core that runs only on Windows host machines. It is an alternative to Kestrel and is built on Http Sys kernel-mode driver. Also, is used for direct connection to the internet without the need of an IIS as a reverse proxy server. It is not compatible with IIS. Core Interview Question

What is IWebHostEnvironment interface used for?

IWebHostEnvironment is an interface for .NET Core. It is used to get information on the web hosting environment an application is executing in. It needs to be injected as a dependency on the controller. The interface has two properties:

Web Root Path – Path of the WWW folder
Content Root Path – Path of the root folder which includes all the application files.

What are the Service lifetimes?

Service lifetimes define the conditions in which a new service instance will be instantiated. Here are the three types of service lifetimes defines by the .NET Core DI framework:

Transient – Instance is created every time they are requested.
Scoped – Per every web request or any unit of work. We call this a scope.
Singleton – Created only for the first request. If the singleton instance is specified at registration time, the instance will be available to all consumers of the registration type.

services.AddTransient<ILifeServiceExample, LifeServiceExample>(); 
services.AddScoped<ILifeServiceExample, LifeServiceExample>(); 
services.AddSingleton<ILifeServiceExample, LifeServiceExample();

What is the difference between UseIIS & UseIISIntegration?

Before ASP.NET Core 2.2, ASP.NET Core was hosted outside of the IIS process. This meant that we had two processes for ASP.NET core application:

w3wp.exe – the IIS Process
dotnet.exe – the ASP.NET Core process. This is where Kestrel web server was started.

IIS and Kestrel communicated between these two mentioned processes. In this case, you need to use UseIISIntegration.

However, in later versions, ASP.NET Core introduced in-process hosting. ASP.NET Core no longer ran separately but runs inside IIS w3wp.exe process. This removes the need for the Kestrel web server. For this case, you would need to specify UseIIS.

Advance Core Interview Question

What are technologies discontinued in .NET Core?

The following technologies have been discontinued in .NET Core:

Reflection – Has been converted into a lightweight version. An extension method called GetTypeInfo exposes information that you normally retrieve from Type object. However, it is not as detailed as the original.
AppDomain – AppDomains isolate apps from each other. They require runtime support and are costly. Creating more app domains is unsupported and there aren’t any plans to add this in the future. Microsoft recommends using separate processes or containers as an alternative.
Remoting – .NET Remoting created several issues in its architectural design. Since it’s used for cross-AppDomain, which is no longer supported, it was decided to not support it either. It also cost them a lot due to runtime support.
Security Transparency – Due to security reasons, Security transparency is no longer supported. It used to separate sandbox code from security-critical code in a declarative method. Microsoft recommends you use security boundaries provided by the operating system itself. Such examples include virtualization, contained or user accounts.

What does Configure Services method do in the startup class?

Configure Services method takes care of registering services which are consumed across the application using Dependency Injection (DI) or Application Services.

public void ConfigureServices(IServiceCollection services) 

What is a Self-hosted Web Application?

ASP.NET Core is fully decoupled from the web server environment hosting the application. It still supports IIS and IIS Express but by default, it uses self-hosting scenarios by using Kestrel and Web Listener HTTP Servers.

Here is a sample of how to configure a web application that is self-host:

public class Program 
     public static void Main(string[] args) 
         var config = new ConfigurationBuilder()
                      .AddEnvironmentVariables(prefix: "ASPNETCORE_").Build(); 

         var host = new WebHostBuilder()
} Core Interview Question

What is a .NET Generic Host?

As of ASP.NET Core 3, they exported ASP.NET code to run on a .NET Generic Host instead of the previously used Web Host. .NET Generic Host is a non-web version of the Web Host that runs on ASP.NET Core. It is an abstraction layer for both Web and non-web functionality.

They decoupled HTTP pipeline from the Web Host API to enable a wider collection of host environments. For example, non-HTTP workloads that used to be in Web Host API were background tasks, messaging, dependency injection (DI), logging and more. Now they have been separated completely using the Generic host. With this abstraction, developers are able to use these mechanisms for console applications, systemmds, windows services, and web applications.

How to configure Logging in ASP.NET Core

ASP.NET Core supports a logging API that works with multiple built-in and third-party logging providers. To set up logging in ASP. NET Core you need to apply the following;

public static IHostBuilder CreateHostBuilder(string[] args) 
        Host.CreateDefaultBuilder(args).ConfigureLogging(logging => 
        }).ConfigureWebHostDefaults(webBuilder => 

In the above example, the Configure Logging() method takes action to delegate Action to configure logging providers. To add custom logging providers, start off by removing all default providers. To do this call Clear Providers(). In our example, we add the Trace Source and Debug providers instead. We also add the Console logging provider to add logs to console too.

What is the difference between Pages and Views ?

Pages is a new page framework that was introduced in .NET core 2.0. Pages is an evolution of the old Web Forms and provides an easier way to generate pages as opposed to MVC.

The Razor Page is very similar in concept to the standard Model View Controller framework. In main difference is that the Model and the controller are included inside the page. Razor Pages provide a simpler development approach when compared to the standard MVC framework.

How to define URL rewriting in ASP .NET Core?

An URL redirection and rewriting task can be done in Configure() method of startup.cs file in ASP .NET Core. Below is the syntax to redirect

app.Use(async (context, next) =>
                var url = context.Request.Path.Value;
                if (url.Contains("/old-page-url"))
                    // rewrite and continue processing
               await next();

In context.Response.Redirect, if you passed second parameter as true then your redirect will work as permanent redirect with 301 as HTTP status, which helps you in Search Engine Optimization (SEO).

Advance Core Interview Question

Explain ASP .NET Core Middleware?

One of the important .NET Core interview questions.

Middleware is a component which gets executed every time a request is made to the ASP .NET Core application. Middleware is similar to HTTP Handlers and HTTP Modules of traditional ASP .NET. In ASP .NET Core, Request delegates are used to build the request pipeline to handle each and every HTTP request. Request delegates can be configured using Run(), Map() or Use() extension methods. We can use these methods in Configure() method of startup.cs file

Middleware in .NET Core

Run() Method

public class Startup
    public void Configure(IApplicationBuilder app)
        app.Run(async context =>
            await context.Response.WriteAsync("Hey There...");

Use() Method
For eg – If you want to redirect your one of old page to the new page, then you have to check each http request to match the UTL containing your old page URL and then redirect to new page.

app.Use(async (context, next) =>
                var url = context.Request.Path.Value;
  if (url.Contains("/old-page-url"))
   await next();

What is API Documentation in ASP .NET Core?

This is another important questions asked to .NET Core Developer.

API documentation is used to help client or non-technical users to understand the .Net Core end points.

This can be done with the help of Swagger. Swagger is an open source technology used for API documentation.

To use Swagger, developer needs to install this package – Swashbuckle.AspnetCore

services.AddSwaggerGen(c=>c.SwaggerDoc("V1", new Info() {Title="My API Doc", Version="V1"}));

In above code V1 is the version number of your API.

What is Razor Pages?

Razor pages are the next evolution of traditional ASP .NET Webform. File extension of razor pages is .cshtml ASP .NET Core Razor Page is very similar to ASP.NET MVC’s view pages. It has a similarity in syntax and functionality as MVC. The major difference is that in an MVC application model and controller code is included or bonded with View pages. Razor Pages vs MVC in .NET Core Core Interview Question

How to define Database connection string in ASP .NET Core?

A database connection string is a very basic task for a developer. But defining a database connection string in .NET Core and reading back into C# code is a little different than the traditional ASP .NET framework. In .NET core, we don’t have web.config like ASP .NET framework. In ASP .NET Core we have JSON based file to manage database connection string.

  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost\SQLEXPRESS;Database=Test;Trusted_Connection=Yes;Integrated Security=SSPI;"
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
  "AllowedHosts": "*"

If you are using entity framework core then, get the connection name in Configure Services() method defined in startup.cs file.

 services.AddDbContext(options =>

In general, use below code to read and use database connection string defined in appsettings.json file

var dbconfig = new ConfigurationBuilder()

if (!string.IsNullOrEmpty(dbconfig.ToString()))
                    string dbconnectionStr = dbconfig["ConnectionStrings:DefaultConnection"];

How to implement Routing in ASP .NET Core?

Routing is a mechanism to match incoming HTTP request and then transfer those request to matching endpoint URL. You will find a defined route in startup.cs file when you create an ASP .NET Core project. In Configure() method, below is the pre-defined routing

 app.UseMvc(routes =>
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

You can define attribute routing in Controller class of ASP .NET Core application –

        public IActionResult Dashboard()
            var listData = _context.DashboardData.OrderBy(x=>Guid.NewGuid()).ToList().Take(10);
            return View(listData);

What are JSON files available in ASP .NET Core project?

Below are the JSON files available in ASP .NET Core project


Advance Core Interview Question

What’s new in .NET Core 3.1 ?

Support of C++/CLI – Support added to create and develop C++/CLI projects. Binaries produced from these projects are compatible with .NET Core 3.0 and later versions.

app Host – When the app Host setting is enabled, .NET Core generates a native Mach-O executable when you build or publish. Your app runs in the context of the app Host when it is run from source code with the dotnet run command, or by starting the Mach-O executable directly.

You can configure the app Host at the project level using below xml code.




Dot Net Core 3.1 is available in which version of Visual Studio?

If you’re using Visual Studio 2019, you must update to Visual Studio 2019 version 16.4 or later to work with .NET Core 3.1 projects.

What are key changes in .NET Core compare to .NET Framework?

ASP.Net Web Forms, Windows Workflow Foundation and ADO .NET Data Services not supported in .NET Core.

Instead of Web Forms, we can use Razor Pages to develop apps in .NET Core. Core Interview Question

What’s new in .NET 5?

Below are few major changes in .NET 5

.NET 5 supports C#9 and F#6.
It supports WindowsArm64
Improved performance of System.Text.Json
Cross-Platform support for System.DirectoryServices.Protocols to work with Directory Services on Linux and MacOs

Where to use .NET 5?

Use .NET 5 for below reasons –

You need cross-platform application
If, You are planning for Microservice architecture
You are using Docker containers.

What is Secret Manager in ASP .NET Core?

This is a common interview question for .NET Core developer.

The Secret Manager tool in ASP .NET Core stores confidential information out side of the project during the development phase. In Windows Machine, secrets.json file path is


To Create User Secrets –

Right click on project name in Solution explorer.
Select Manage User Secrets. You may notice that a JSON file secrets.json is now created.
Now cut the connection string node from appsettings.json file and paste it into secrets.json file.
Build your project and run your application. It should work perfectly.
Secret Manager works only in development machine.

Advance Core Interview Question

How to implement Dependency Injection in .NET 5?

This is one of the most frequently asked .NET Core interview Question.

.NET 5 supports the dependency injection (DI) software design pattern, which is a procedure for accomplishing Inversion of Control (IOC) among classes and their conditions.

Dot Net 5 injects objects of dependency classes using a constructor or a method by utilizing IOC container.

ASP .NET Core or .NET 5 allows us to enlist our application code with IOC container, in the Configure Services method of Startup class (startup.cs).

The Configure Services method incorporates a parameter of IService Collection type which is utilized to enroll application services.
A service can be injected into the Startup constructor and the Startup. Configure method.

What is appsettings.Environment.json file in .Net Core?

By default, an appsettings.json file and appsettings.Development.json file is created in .NET Core project.

We can create multiple app settings file based on environment in .NET Core, for development we have appsettings.Development.json, for staging we can create appsettings.Staging.json and for production we can have appsettings.Production.json file.

What are differences between .NET Framework vs .NET Core vs .NET 5 ?

ASP.NET Framework is a Windows-only version of .NET for building any type of app that runs on Windows. It means .Net framework is built for Windows machine only.

.NET Core is a free, cross-platform, open-source developer platform for building many different types of applications. The first version .NET Core 1.0 was released in June 2016 and the last version of .NET Core is 3.1 which was released in Dec, 2019.

.NET 5 is a free, cross-platform, open-source developer platform for building many different types of applications. .NET 5 is the next major release after .NET Core 3.1 which was released in June, 2016.

The word ‘Core’ is dropped from the name to emphasize that .NET 5 is the future of all earlier versions of .NET Core. Core Interview Question

How to implement Repository pattern in ASP.Net Core project?

It is a very popular design pattern used widely.

To implement repository pattern in ASP .NET Core project, follow this –

Create an interface and declare the methods inside this interface.
Add a repository class and implement the interface created in step 1.
Place dB Context dependent code in Repository class.
Register Interface and repository class in startup.cs
In Controller class, call the CRUD methods defined in interface.

What is Content Negotiation?

In REST API, there is a defined format for Input and Output data.

By default, ASP .NET Core API supports JSON format.

To get response in XML format, add below line in Configure Service() method in startup.cs file


Now, if you provide accept header value to application/xml then API will respond in XML format.

What is ASP .NET Core Identity?

ASP .NET Core Identity provides a wide range of helper functions to perform essential core features related to user identity management. For example – Password hash, Account Confirmation, Multifactor Authentication etc.

Advance Core Interview Question

What is State full and Stateless authentication?

Stateful AuthenticationStateless Authentication
It means that server keep tracks the session and a cookie is created in user’s browser.Each request is tied with a token to verify the request. It uses JWT (JSON Web Token) to validate the user.
It is called Cookie based authentication.It is called Token based authentication. Core Part Core 3

Back to top