Top Interview Questions .NET Core

  • Reading time:4 mins read

List out basic .NET Core Interview questions.

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

ASP.NET Core comes with the following benefits over ASP.NET.

  • Cross platform, provide ability to develop and run on Windows, Linux and MacOS.
  • Open-source
  • Unified Platform to develop Web UI and services.
  • Built-in dependency injection.
  • Ability to deploy on more than one server like IIS, Kestrel, Nginx, Docker, Apache etc
  • cloud enabled framework, provide support for environment based configuration system.
  • Lightweight, High performance and modern HTTP request pipelines.
  • well suited architecture for testability

Can ASP.NET Core work with the .NET framework?


What does WebHost.CreateDefaultBuilder() do?

  • 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 Startup.cs file in ASP.NET Core?

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 ConfigureServices() 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.
  • ConfigureServices is used to add services to our application
  • We can use services via integrated DI once we add them inside of ConfigureServices
  • Services added to DI can be utilized within our application

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 IApplicationBuilder instance that is provided by dependency injection.

What is middleware?

In ASP.NET Core, middleware are C# classes that can handle an HTTP request or response. Middleware can either:

  • Handle an incoming HTTP request by generating an HTTP response.
  • Process an incoming HTTP request, modify it, and pass it on to another piece of middleware.
  • Process an outgoing HTTP response, modify it, and pass it on to either another piece of middleware, or the ASP.NET Core web server.

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).

What is Kestral?

Kestrel is a cross-platform web server for ASP.NET Core based on libuv, a cross-platform asynchronous I/O library

What is wwwroot folder?

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.

Explain Session and State management in ASP.NET Core

As we know HTTP is a stateless protocol. HTTP requests are independent and does not retain user values. There are different ways to maintain user state between multiple HTTP requests.

  • Cookies
  • Session State
  • TempData
  • Query strings
  • Hidden fields
  • HttpContext.Items
  • Cache

What is attribute routing?

Attribute routes are applied to controllers and actions directly, rather than specified globally.

Attribute routing example:

public ActionResult Show(int reviewId) { … }

Leave a Reply