preloader
ASP.Net Core Interview Questions

Top ASP.NET Core Interview Questions and Answers for Upcoming Interviews

author image

You are looking for a job in ASP.NET Core, but you don’t know where to begin. It’s important that you know what the hiring managers look for when hiring for ASP.NET Core developer. So, to help you out, here are a few ASP.NET Core Interview Questions to prepare for an upcoming job interview. Here, we have given questions for all levels i.e. freshers, intermediate, experienced to ace the job interview after preparing from these ASP.NET Core Interview Questions & Answers.

About ASP.NET Core: ASP.NET Core is a web application framework developed by Microsoft. It was first released in June 2016. ASP.NET Core is a modular and lightweight web application platform. It can be used to develop different kinds of websites including simple ones such as single-page applications and dynamic ones like portal websites.

ASP.NET Core Interview Questions

1. Explain ASP.NET Core?

2. What are the features ASP.NET Core offers?

3. Tell me the benefits of ASP.NET Core over ASP.NET?

4. Explain Host in ASP.NET Core?

5. Explain Metapackages?

6. Is ASP.NET Core application is able to work with full .NET 4.x Framework?

7. Explain startup class in ASP.NET core?

8. Tell me the use of ConfigureServices process of startup class?

9. Explain the way to use Configure method of the startup class?

10. Explain the Web Host and Generic Host.

11. Explain Options Pattern in ASP.NET Core?

12. Tell me the way to use numerous environments in ASP.NET Core?

13. How does Routing work in ASP.NET Core?

14. What do you understand by Session and State management in ASP.NET Core?

15. Can Docker containers run ASP.NET applications?

16. Can you provide a quick example of how to use an ASP.NET Core application with your personal website or blog?

17. Which do you think is more suitable for beginners, .NET Core or .NET MVC?

18. What are some of the things that you like and dislike about the new framework?

19. Which would you choose to go in a client-server application? ASP.NET Core or .NET MVC?

20. How does ASP.NET Core perform static files?

21. Describe Response Caching or caching in ASP.NET Core.

22. Explain In-memory cache?

23. Explain Distributed caching?

24. Explain the Area?

25. Explain ASP.NET Core MVC.

26. Explain the View-Model

27. Explain the View-Model

28. Describe strongly-typed views.

29. What's the use of Map.Use() when adding middleware to the ASP.NET Core pipeline?

30. How to allow Session in ASP.NET Core?

31. Name different JSON files available in ASP.NET Core?

32. Tell me the way to disable Tag Helper at element level?

33. Explain Razor Pages in ASP.NET Core?

34. Tell me the way of automatic model binding in Razor pages?

35. Explain Startup.cs file in ASP.NET Core?

36. What is the purpose of the Program class?

37. Explain the role of the wwwroot folder?

38. What is the purpose of the appsettings.json file?

39. What is IIS?

40. Explain Kestrel?

41. What’s the HTTPContext object? How can you access it within a Controller?

42. Explain a cookie?

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

44. Differentiate between SDK and Runtime in .NET Core?

45. What are the advantages of using explicit compilation?

46. What are service lifetimes in .NET Core?


Learn More Interview Questions Here:


ASP.NET Core Interview Questions & Answers

1. Explain ASP.NET Core?

As many think, ASP.NET Core is not an enhanced or upgraded version of ASP.NET. It is a fully rewritten work with the help of the .net Core framework. It is much quicker, modular, configurable, extensible, scalable, and has cross-platform support. It can perform with both .NET Core and .net framework through the .NET standard framework. It is well-suited for creating cloud-based applications like web applications, IoT applications, mobile applications, etc.

2. What are the features ASP.NET Core offers?

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

  • In-Built support for Dependency Injection.
  • The logging framework has inbuilt support.
  • Kestrel, a new web server for Windows, Linux and macOS, was introduced. This will allow web applications to run without the IIS, Apache, and Nginx.
  • Multiple hosting options are supported.
  • The application must be able to use any JavaScript module, so the application requires that you include all modules required by it. The NET Core framework also offers a meta-package, which includes the libraries
  • The command line allows for the creation, building, and running of the application
  • There is no web.config file. Instead, we can store the custom configuration in a JSON file.
  • There is no global.asax file. We are able to register and use the services in a class file.
  • It supports asynchronous programming.
  • Support SignalR & WebSocket
  • Provide protection against Cross-Site Request Forgery (CSRF).

3. Tell me the benefits of ASP.NET Core over ASP.NET?

Here are some benefits of ASP.NET Core over ASP.NET :

  • ASP.NET Core provides cross-platform, so it can operate on Windows, Linux, and Mac.
  • There is no framework installation dependency because all the necessary dependencies already come with our application
  • ASP.NET Core can manage more requests than the ASP.NET
  • Multiple deployment alternatives are available withASP.NET Core

4. Explain Host in ASP.NET Core?

It encapsulates all the resources for the application. When started ASP.NET Core application build the host. Some of the resources that Host encapsulate are:

  • HTTP Server implementation
  • Dependency Injection
  • Configuration
  • Logging
  • Middleware components

5. Explain Metapackages?

The framework .NET Core 2.0 presented Metapackage that contains all the sustained packages by ASP.NET code with their reliances into a single package. It enables us to do rapid development as we don’t need to contain the particular ASP.NET Core packages. The Microsoft.AspNetCore.All is a meta-package delivered by ASP.NET core.

6. Is ASP.NET Core application is able to work with full .NET 4.x Framework?

Yes, ASP.NET core application is able to works with full .NET framework through the .NET standard library.

7. Explain startup class in ASP.NET core?

It is the entrance point of the ASP.NET Core application and each .NET Core application has this class. This startup class includes the application configuration-related items. It isn't mandatory that the class name must be "Startup", we can organize the startup class in the 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>();
}

8. Tell me the use of ConfigureServices process of startup class?

It is an optional method that can be utilized to configure the services used by an application. When the application is requested for the first time this procedure is called first. Using this procedure, we add services to the DI container, so services are known as a dependency in the controller constructor.

9. Explain the way to use Configure method of the startup class?

It describes how the application will answer each HTTP request. We can pipeline the request by organizing the middleware. It takes IApplicationBuilder as a parameter. Other than this two optional parameters are also used which are IHostingEnvironment and ILoggerFactory. By this method, we are able to configure built-in middleware like authentication, routing, session, etc. as well as third-party middleware.

10. Explain the Web Host and Generic Host.

The host sets up the server, demand pipeline and is accountable for app startup and lifetime administration. There are two hosts:
ASP.NET Core Web Host
.NET Generic Host
ASP.NET Core Web host is utilized for backward compatibility.
.NET Generic Host is recommended to use whereas ASP.NET Core template creates a .NET Generic Host on app startup.
 
// Host creation
public class Program
{
	public static void Main(string[] args)
	{
    	CreateWebHostBuilder(args).Build().Run();
	}
 
	public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        	.UseStartup();
}

11. Explain Options Pattern in ASP.NET Core?

It enables you to access related formatting settings by using some classes in a powerful typed way. When you are using the configuration settings with the isolated classes then the applications should stick to these two principles.

  • Encapsulation or Interface Segregation Principle (ISP): The class that relies on the configurations, basically relies only on the configure settings that they use.
  • Separation of Concerns: Settings for various classes should not be connected or dependent on each other.

12. Tell me the way to use numerous environments in ASP.NET Core?

ASP.NET Core configure application behavior by using environment variables that are based on the runtime environment. launchSettings.json sets ASPNETCORE_ENVIRONMENT to Development on local Machine.

13. How does Routing work in ASP.NET Core?

It manages incoming HTTP requests for the application. Routing sees a similar executable endpoint for coming requests. These endpoints are recorded when the application starts. The matching process takes help from values from the incoming request URL to execute the requests. You can configure the routing in the middleware pipeline of configuring technique in the startup class.
 
	app.UseRouting(); // It adds route matching to middlware pipeline
 
	// It adds endpoints execution to middleware pipeline
	app.UseEndpoints(endpoints =>
	{
	endpoints.MapGet("/", async context =>
	{
	await context.Response.WriteAsync("Hello World!");
	});
	});

14. What do you understand by Session and State management in ASP.NET Core?

We all know that HTTP is a stateless protocol. HTTP requests are independent in nature and don’t control user values. TBy using these ways you can maintain user state between multiple HTTP requests.

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

15. Can Docker containers run ASP.NET applications?

Yes, Docker containers can run an ASP.NET application or .NET Core application.

16. Can you provide a quick example of how to use an ASP.NET Core application with your personal website or blog?

A personal blog is just about the simplest scenario to show off without too much modification. ASP.NET Core gives some great powers over content to your application, like directly configuring ViewBag from an environment variable with a web.config property name and setting up middleware as plugins on different controllers with easily-remembered names; however, it’s not that hard either if you prefer modifying by hand things in the many configuration files manually (or prefer Visual Studio ). First, create an ASP.NET Core application:

1 2 3 4 5 6 $ dotnet new myweb –name MyWeb -t should be obvious which we convert to a personal website with the app namespace and call TresCredenius because I like writing acronyms for all of our websites…

Figure out where you need to put your site on your file system. For this set up, we will put our project under the “““C:\fake”” web url. This can be achieved by modifying the WebApi RouteHandler in Startup class:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 using Microsoft.

17. Which do you think is more suitable for beginners, .NET Core or .NET MVC?

There are pros and cons to both choices. I would choose a hybrid application like ASP.NET Core if possible so that you can decide at the start of your project which technology layers need to be used (web, network, or data access). Both MVC and code-first approaches make it easy but with Microsoft software development every decision is a choice.

18. What are some of the things that you like and dislike about the new framework?

There are a lot of good things about ASP.NET Core - it’s easy to use and understand for non-programmers, equally scalable on cloud servers as well as physical ones (on the same machine or with separate virtual hosts), fast startup times, etc… The storage mechanism that handles database connections is also really smooth - no more upgrading during production over slow internet links! There is not much static content in this setup so we will leave how it is rendered for later (in the next blog post).

19. Which would you choose to go in a client-server application? ASP.NET Core or .NET MVC?

I like the implementation of different technologies that allows one team to use both languages to write and manage two experiences - a traditional website backed by API and an experience built with HTML & JavaScript, which is called modern web apps. The challenge comes from getting business-level people to understand that an app isn’t a website and must be approached with different design assumptions. It is easy to fall into the trap of keeping most data in “apps” due to similarities in UI conventions but you don’t sell apps.

20. How does ASP.NET Core perform static files?

Static files such as CSS, images, JavaScript, HTML files are served directly from your ASP.NET Core web application. The ASP.NET Core template provides the root directory and the wwwroot folder which have all the static files. UseStaticFiles() is called in the Startup.configure to add the static file served to the client. Configuration allows the static files to be served outside of this webroot folder.
You can serve files outside of this webroot folder by configuring Static File Middleware as follows.
 
app.UseStaticFiles(new StaticFileOptions
	{
    	FileProvider = new PhysicalFileProvider(
            Path.Combine(env.ContentRootPath, "MyStaticFiles")), // MyStaticFiles is new folder
    	RequestPath = "/StaticFiles"  // this is requested path by client
	});
// now you can use your file as below
<img src="/StaticFiles/images/profile.jpg" class="img" alt="A red rose" />
 // profile.jpg is image inside MyStaticFiles/images folder

21. Describe Response Caching or caching in ASP.NET Core.

Caching can significantly improve performance by reducing the number of calls to data sources. It makes the scalability much better. An effective way of improving scalability is through response caching. Caching copy data and stores it instead of fetching it from the actual source.

The ResponseCache element sets the caching headers for response caching. ResponseCache can be used to set additional properties on a response.

Know the Interview Criteria of these MNCs!!!

ASP.NET Core Interview Questions and Answers For Experienced

22. Explain In-memory cache?

It stores the data in RAM on the web server, making it a faster and more efficient way of caching than other solutions.

Applications that run on multiple servers need to ensure the session data is sticky and stored in-memory to help it run faster. A sticky session is a PHP function or class that is designed to redirect subsequent client requests to the same server. The class itself is an in-memory object; this means that all the data stored within is stored in memory. An in-memory cache can keep any object but distributed cache only stores byte[].

This allows you to add your implementation of IMemoryCache by using dependency injection with ASP.NET Core dependency injection mechanism in a constructor.

23. Explain Distributed caching?

Applications running on a web farm should have their session state saved in a shared database. The application should make the session sticky. Non-sticky sessions could cause caching inconsistencies between servers. Distributing caches can help alleviate some of the problems with consistent memory management. Caching in a distributed environment has certain advantages.

  • Data remains constant from one request to the next.
  • Data is not deleted during a server restart.
  • Data doesn’t need local memory.

Distributed caching service provided by any constructor of the IDistributedCache interface allows simply creating a cache via Dependency Injection.

24. Explain the Area?

ASP.NET MVC applications can be divided into several functional areas or subsystems. Normally, the Models, Views, and Controllers of an ASP.NET MVC application will be separated into distinct folders to ensure that all functions of the application are contained within their area. But Area is an MVC framework that separates an application into multiple functional groups. For example, for an e-commerce site, the Billing, Orders, search functionalities can be implemented using different areas.

25. Explain ASP.NET Core MVC.

ASP .NET Core MVC is a programming framework for building web applications and APIs. The ASP.NET Core MVC technology uses the Model-View-Controller (MVC) design pattern. In MVC, a single class contains three roles: the model, view, and controller. It’s also important for a project to be delivered in the design of separation of concerns (SoC) principles. ASP.NET Core MVC is an open-source framework for building modern Web applications and services with .NET Core.

26. Explain the View-Model

ViewModel is used to pass complicated data from controller to view. The data of ViewModel is prepared from various models and passed to view to display that data. For example, a complicated data model can be passed by using a ViewModel pattern .

Class Author{

public int Id {get;set;}

public Book Book {get;set;}

}

Class Book{

public string Name {get;set;}

public string PublisherName {get;set;}

}

This Author and Book data can be viewed when creating BookViewModel inside a controller.

27. Explain the View-Model

ViewModel is used to pass complicated data from controller to view. The data of ViewModel is prepared from various models and passed to view to display that data. For example, a complicated data model can be passed by using a ViewModel pattern .

Class Author{

public int Id {get;set;}

public Book Book {get;set;}

}

Class Book{

public string Name {get;set;}

public string PublisherName {get;set;}

}

This Author and Book data can be viewed when creating BookViewModel inside a controller.

28. Describe strongly-typed views.

The definition of a strongly typed view implies that the binding between the view and its model is strong. Therefore, if you want to pass data from the controller to the view, you need to use a strongly-typed view. A controller can pass a strong type model to the view, enabling full type checking and IntelliSense support in the view.

29. What's the use of Map.Use() when adding middleware to the ASP.NET Core pipeline?

This node is used to branch pipelines. This node branches the ASP.NET Core pipeline on the basis of request path matching. When the request path starts with the given path, the middleware on to that branch will perform.

public void Configure(IApplicationBuilder app)

{

app.Map("/path1”, Middleware1);

app.Map("/path2”, Middleware2);

}

30. How to allow Session in ASP.NET Core?

Microsoft ASP.NET Core provides a Session middleware for the session. The ASP.NET Core application must be configured to use the Session middleware. The csproj file must have the add Session middleware to the 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();
….
….
}
}

31. Name different JSON files available in ASP.NET Core?

  • package.json
  • bundleconfig.json
  • global.json
  • appsettings.json
  • launchsettings.json
  • bower.json

32. Tell me the way to disable Tag Helper at element level?

You can disable Tag Helper from the element level by adding the HTML comment character ("!"). To open and close an Html tag, this character must be used. Example

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

33. Explain Razor Pages in ASP.NET Core?

This is a new feature in ASP.NET Core 2.0 that follows the page-centric development model used in previous versions of ASP.NET. Net Web Forms. It offers all the features of ASP .NET Core. Example

@page

Hello, Book Reader!

This is Razor Pages

Razor pages start with the @page directive, which handles a request directly without going through the controller. When Razor pages were initially introduced as a concept, the Razor pages could have a code**-**behind files considered to be a .cs file in disguise. A class inherited from the PageModel class contains the logic of the Razor pages.

34. Tell me the way of automatic model binding in Razor pages?

Razor pages let you bind properties as you post data with the BindProperty attribute. By default, it only binds the properties to non-GET verbs. We need to set SupportsGet to true in order to enable binding to property. Example:

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

35. Explain Startup.cs file in ASP.NET Core?

If you are using ASP.NET MVC, the Global.asax class acts as the gateway into your application. If you use ASP.NET WebForms, it’s the Startup.cs file that acts as the starting point of your application. The Startup class configures the request pipeline that handles all requests made to the application.

36. What is the purpose of the Program class?

Program.cs file is the starting point of any ASP.NET project. For a Windows application, the entry point method is defined in Program.cs. This file has the signature of a static void Main() function.

This class configures the web host that will serve the requests. The host is responsible for application startup and lifetime management, including graceful shutdown.

In this case, you must have a server and a request processing pipeline, because the server can also manage logging, configuration, and dependency injection.

37. Explain the role of the wwwroot folder?

Static files and compiled assets such as JavaScript, CSS, and images are included in the root folder of a web project. The only folder that is visible to the web browser is wwwwroot, which is the root folder of the project.

38. What is the purpose of the appsettings.json file?

Appsettings.json contains all the configuration options for your application, which allows you to configure your application's behavior. For example:

{
"Logging": {
 	"LogLevel": {
      	"Default": "Information",
	"Microsoft": "Warning",
	"Microsoft.Hosting.Lifetime": "Information"
  	}
  },
"ConnectionStrings": {
	"AppConnection": ""
},
"AWS": {
  "Profile": "local-test-profile",
  "Region": "us-west-2"
},
"AllowedHosts": "*"
}

39. What is IIS?

In the world of the Internet, the Internet Information Services (IIS) server is a common program used by organizations that offer Internet hosting services. IIS was developed and released in 1998 by Microsoft. IIS allows you to add multiple web servers to your network with less maintenance than using a single server.

As a reverse proxy, it accepts requests from clients and forwards them to an application server. A reverse proxy improves security, reliability, and performance.

IIS is highly configurable. It will run only on any Windows OS version including Windows 95, 98, ME, NT, 2000, and later, starting with Windows XP

40. Explain Kestrel?

Kestrel is a free, cross-platform ASP.NET Core web server designed for the development and deployment of websites and services. ASP.NET Core is small and lightweight when compared with IIS. Kestrel is a web server that runs on Linux operating system.

However, Kestrel can serve an ASP.NET Core application on its own, but it’s recommended to use it with a reverse proxy server like IIS, Nginx, or Apache to provide better performance, security, and reliability.

41. What’s the HTTPContext object? How can you access it within a Controller?

The HttpContext class encapsulates HTTP-specific information for a single HTTP request. This information is used by ControllerBase.HttpContext to make decisions for example:

public class HomeController : Controller
{
  public IActionResult About()
  {
  	var pathBase = HttpContext.Request.PathBase;
 
  	...
 
  	return View();
  }
}

A cookie is a small piece of data that is sent to the browser each time a website is visited by a user. It can contain information such as login IDs, passwords, and other personal information. Cookies are stored on the browser. Most browsers use a cookie format that consists of an alphanumeric key and a value, often, it is simply the name of the website visited by the user.

Write a cookie in ASP.NET Core:

Response.Cookies.Append(key, value);

Delete a cookie in ASP.NET Core

Response.Cookies.Delete(somekey);

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

Yes. You may be surprised to learn that ASP.NET Core works with the .NET framework and Microsoft officially supports that as well.

ASP.NET Core works with:

  • .NET Core framework
  • .NET framework

44. Differentiate between SDK and Runtime in .NET Core?

The SDK is all the things you need for developing a .NET Core application. It includes the CLI and a compiler.

The runtime provides a virtual machine on which the application runs, and abstracts all the interactions with the operating system.

45. What are the advantages of using explicit compilation?

This makes AOT faster than start-up times for older software, especially for very large applications with lots of code. The size of the runtime data structures is far larger than that for a native process, and they require additional memory for storing both the IL and precompiled images. In the best case, it can avoid a lot of I/O operations, but in general, the JIT compiler will require a lot of disk I/O.

46. What are service lifetimes in .NET Core?

.Net Core introduces a design pattern named Dependency Injection (DI) by using an implementation of IoC(Inversion of Control) that provides an easy way to get hold of services by the business logic. Dependencies also demand that its life cycle must be well defined. There is a range of life cycles for instances of a service. The various states of an instance of the service are controlled by the conditions of its life cycle.

There are three types of support lifetimes for .NET Core:

  • Transient Service: An instance is made every time you request it.
  • Scoped Service: There is one user-specific instance for each user. This instance is shared between all requests.
  • Singleton Service: Single-instance applications are created once and only once per lifetime of the application.

Want to prepare for these languages:

Recent Articles