5 Most Asked ASP.NET CORE Interview Question & Answer

/ / 1 Comments

ASP.NET CORE Interview Question & Answer : Here in this article we see top 5 most asked ASP.NET CORE interview questions and answers. I am sure 2 question out of these 5 will definitely going to asked in your any asp.net core interview.  

Following are the 5 most asked ASP.NET CORE interview questions:

  1. What is Middleware in Asp.net Core?
  2. What is the difference between app.Use and app.Run()?
  3. What is dependency injection in ASP.NET CORE?
  4. What is routing in ASP.NET Core?
  5. How to enable Session in Asp.net Core?

You can also check YouTube Video:


Let's answer each interview question one by one.

Q1) What is Middleware in Asp.net Core?

  • Middleware is a component (logic code), which gets executed on each HTTP request in the Asp.net Core application. 
  • Middleware is injected into the application pipeline to handle request and responses.
  • Each middleware adds or modifies the HTTP request and optionally passes control to the next middleware component.
  • Middlewares are registered under the Configure method in the Startup.cs file.
  • Asp.net Core has many built-in middlewares which can be added via Nuget or we can also create custom middleware.
  • We can register as much middleware as we want, but the ordering is important.

Q2) What is the difference between app.Use and app.Run()?

  • First of all both methods are used to registered middleware, to the application request pipeline. 
  • The only difference is middleware defined using app.Use may call next middleware component in the pipeline. On the other hand, middleware defined using app.Run will never call subsequent middleware.
  • It means app.Run acts as a terminal middleware, and so no other middleware method will run after this.

Sample Code:

Q3) What is dependency injection in ASP.NET CORE?

  • Dependency Injection is one of the most known strategies that help us to create more maintainable code, and.NET CORE has inbuild supports for Dependency Injection.
  • Dependency Injection ( also known as DI) is a technique that helps to inject a dependent object of a class or we can say it helps us to create loosely coupled applications.
  • In Startup.cs file under the ConfigureServices method we registered the services, and to register the services we have 3 options i.e AddSingleton, AddScoped, AddTransient
  • Once the service is registered, it is available in DI container and we can access it through constructor injection.

Sample Code:

Q4) What is routing in ASP.NET Core?

  • Routing is a pattern matching system, that monitors the incoming request and figures out what to do with that request.
  • It is the process through which the application matches an incoming URL and executes the corresponding Controller action methods.
  • Asp.net core supports two types of routing i.e Conventional routing and Attribute routing.

Routing Flow Diagram:

Q5) How to enable Session in Asp.net Core?

  • The session is used to store or save user data.
  • To enable sessions in asp.net core we need to add AddSession() method in the ConfigureServices method of our Starup.cs file.
  • Next, we need to add app.UseSession() middleware in the Configure method.
  • To set session we use HttpContext.Session.SetString or  HttpContext.Session.SetInt32
  • To get session value we use HttpContext.Session.GetString or  HttpContext.Session.GetInt32.

Sample Code:


Thank you for reading, pls keep visiting this blog and share this in your network. Also, I would love to hear your opinions down in the comments.

PS: If you found this content valuable and want to thank me? 👳 Buy Me a Coffee

Subscribe to our newsletter

Get the latest and greatest from Codepedia delivered straight to your inbox.


Post Comment

Your email address will not be published. Required fields are marked *

1 Comments