Asp.net Core Interview Questions Answers

This post is about ASP.NET Core Interview Questions. These questions are good enough to assess a candidate if he/she has working knowledge about Asp.Net Core, These are kind of guidelines for core ASP.NET Core concepts and some experience in real-time application development using Asp.net Core.

Top Online Courses 2021 (Offering Discount)

ASP.NET MVC Interview Questions Answers

If you are job seeker or going for ASP.NET Core interviews, this will help you to get ready for potential questions be asked during interview.

If you are beginner, then i suggest you should go through basic .net framework related questions first, which will remain almost same for all frameworks, here they are!

Asp.net core job interview questions

What is CTS?
Learn more about Common Type System.

What is CLR?
Learn more about Common Language Runtime.

What is CLS?
Learn more about Common Language Specification.

What is FCL?
Learn more about Framework Class Library.

What is .NET Core?
Asp.NET Core is a newer version of .NET, which is cross-platform, supporting Windows, MacOS and Linux, and can be used in device, cloud, and embedded/IoT scenarios.
What is Kestrel ?
Kestrel is a cross-platform web server built for ASP.NET Core. . It is based on asynchronous I/O library called "libuv" primarily developed for Node.js
It is default web server, but you still can use IIS, Apache, Nginx etc.
Main characterestics of ASP.NET Core?
Here are the Top 10 Asp.Net Core features
  • Cross-Platform webserver "Kestrel" & Container Support
  • Single programming model for MVC and Web API
  • Dependency Injection is heavily used in asp.net core framework, We can extend it with other popular DI containers
  • We have built-in and extensible structured logging in Asp.Net Core, also can use third party logging utility
  • "WWWROOT" folder for static files
  • fully async pipeline easily configured via middleware
  • Razor page, specially designed for small size application, supports cross platform deployment
  • Provide protection against CSRF (Cross-Site Request Forgery)
  • Support WebSocket and SignalR
  • Command-line supports to create, build, run an application
  • Tags Helpers in Asp.net Core helps in rapid Development.
  • There is no web.config, We now use appsettings.json file to store configuration information
  • There is no Global.asax, We have Startup.cs, to setup new Middleware and services for DI Container.
Where to keep configuration information in asp.net core.
Now there is no web.config file, in Asp.net core we have to store configuration information in asppsettings.json file, which is plain text file, keep information as key-value pair in json format .
{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      //"Default": "Warning"
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "DbConnectionConfig": {
    "DatabaseName": "databaseName",
    "UserName": "username",
    "Password": "password",
    "ServerName": "IP-Address"
  }
}
What is Middleware in ASP.NET Core?
Middleware is software injected into the application pipeline to handle request and responses. Now we can manipulate http request and response which was not possible with earlier Asp.net Framework, Middleware are just like chain to each other and formed as a pipeline. We can change the order in configuration

Learn more about asp.net core middleware.

What is the startup class in ASP.NET core?
Startup class is the entry point of any ASP.NET Core application, This class contains the application configuration rated details, it has two main method ConfigureServices() and Configure()
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvc().AddRazorOptions(opt =>
            {
                opt.PageViewLocationFormats.Add("/Pages/shared/{0}.cshtml");
            });
        }
     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
        }
    }
       
What are advantages of ASP.NET Core compare to ASP.NET?
Here are the key advantages of using Asp.Net Core
  • It supports cross-platform application building, so it can be run on Windows, Linux and Mac.
  • Now no framework installation required, because all the required dependencies are packaged with asp.net core application
  • Asp.Net Core has in-built logging capabilities
  • ASP.NET Core can handle request more efficiently than the ASP.NET
What is Configure method of startup class, what does it do?

It defines the HTTP pipeline, how the application will respond to request. We can change the sequence of middleware configuration, it accepts IApplicationBuilder as a parameter and two optional parameters: IHostingEnvironment and ILoggerFactory.

Using this method, we can configure built-in middleware such as authentication, error handling and also any custom middleware or third-party middleware.

Difference between IApplicationBuilder.Use() and IApplicationBuilder.Run()?

Both methods are used to add middleware delegate to the application request pipeline.

Use method may call the next middleware in the pipeline.

Run method never calls the subsequent ore next middleware, After IApplicationBuilder.Run method, system stops adding middleware in pipeline

Explain routing in ASP.NET Core?
Routing is the functionality that map incoming request to the route handler. There are two type of routing supported by ASP.NET Core
  • Conventional routing
  • Attribute routing
How to enable Session in ASP.NET Core?

The middleware for the session is provided by Microsoft.AspNetCore.Session. To use the session in ASP.NET Core application we need to add the middleware in pipeline

public class Startup
 {
     public void ConfigureServices(IServiceCollection services)
     {  
         services.AddSession();
         services.AddMvc();
     }
     public void Configure(IApplicationBuilder app, IHostingEnvironment env)
     {
        app.UseSession();
     }
 }
What are the different JSON files available in ASP.NET Core?
  • appsettings.json
  • bundleconfig.json
  • global.json
  • npm-shrinkwrap.json
  • launchsettings.json
  • bower.json
  • package.json
How automatic model binding in Razor pages works?

When we create a razor page, it provides the option to have model binging or not, in model binding there is a model created with the razor page, the model is inherited from : PageModel we need to use [BindProperty] attribute to bind any property to model

Here is an example
public class ContactModel : PageModel
 {
     [BindProperty]
     public string StudentName { get; set; }
 }
What is the use "Configure" method of startup class?
In "Configure" method we can define each HTTP request and how they will respond in application. In "Configure" method there is IApplicationBuilder parameter
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
}
There are two other parameters IHostingEnvironment and ILoggerFactory, Even we can define different pipeline for different development environment
if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseBrowserLink();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
    }
We also can configure third-party middleware.
What is Metapackage in Asp.Net Core?
In ASP.NET Core project we don’t need to include individual package references in the .csproj file. There is one file called “Microsoft.AspNetCore.All” is added under NuGet, now “Microsoft.AspNetCore.All” contains all the required packages. That’s the concept of metapackage, you can check all files added under that package by expanding following file in your project solution, “Dependencies” => “NuGet” => “Microsoft.AspNetCore.All”
What is Microservices in Asp.Net Core?
Microservices are type of API service, that are small, modular, can be deployed independently, which can run in an isolated environment. Read more about Microservices Design Principal
What are the different return types of a controller action method?
  • ViewResult

    Represents HTML and markup.

  • JsonResult

    Represent JSON that can be used in AJAX, like a JSON object

  • JavaScriptResult

    Represent a JavaScript script.

  • ContentResult

    Represents string literal.

  • RedirectResult

    Represents a redirection to a new URL

  • RedirectToRouteResult

    Represent another action of same or other controller

  • PartialViewResult

    Returns HTML from Partial view

  • HttpUnauthorizedResult

    Returns HTTP 403 status

  • FileContentResult / FileStreamResult / FilePathResult

    Represents the content of a file

How to branch the middleware pipeline?

We can write following code in Startup.cs file.

Here are some sample two Middleware pipeline, we want to map them for different path.

private static void ExecuteMiddleware1(IApplicationBuilder app)
{
app.Run(async context =>
{
await context.Response.WriteAsync("Execute Middleware 1");
});
}
private static void ExecuteMiddleware2(IApplicationBuilder app)
{
app.Run(async context =>
    {
        await context.Response.WriteAsync("Execute Middleware 2");
    });
}

Here is how you can Map Middleware in Configure method

public void Configure(IApplicationBuilder app)
{
app.Map("/mapPath1", ExecuteMiddleware1);
app.Map("/mapPath2", ExecuteMiddleware2);
app.Run(async context =>
        {
            await context.Response.WriteAsync("Hello from No Match.");
        });
    }

Hope these above questions answer will help you to get ready for asp.net core interview, if you have more time, please check our free Asp.net Core tutorial with Code Sample

Here are some Asp.net core development service providers who often asks similar type of question when asses any candidate.

  • Asp.net core freelance developer team doing application development, also help big companies for asp.net developer recruitment

Asp.net Course Online, Learn Asp.Net MVC, Asp.net Core with C#
ASP.NET Course Online
Asp.net Course Online
learn asp.net core
Interview Question Answers | Fresher Job Interview Tips