Skip to main content

Junior .NET Core Interview Questions

Curated Junior-level .NET Core interview questions for developers targeting junior positions. 20 questions available.

Last updated:

.NET Core Interview Questions & Answers

Skip to Questions

Welcome to our comprehensive collection of .NET Core interview questions and answers. This page contains expertly curated interview questions covering all aspects of .NET Core, from fundamental concepts to advanced topics. Whether you're preparing for an entry-level position or a senior role, you'll find questions tailored to your experience level.

Our .NET Core interview questions are designed to help you:

  • Understand core concepts and best practices in .NET Core
  • Prepare for technical interviews at all experience levels
  • Master both theoretical knowledge and practical application
  • Build confidence for your next .NET Core interview

Each question includes detailed answers and explanations to help you understand not just what the answer is, but why it's correct. We cover topics ranging from basic .NET Core concepts to advanced scenarios that you might encounter in senior-level interviews.

Use the filters below to find questions by difficulty level (Entry, Junior, Mid, Senior, Expert) or focus specifically on code challenges. Each question is carefully crafted to reflect real-world interview scenarios you'll encounter at top tech companies, startups, and MNCs.

Questions

20 questions
Q1:

What are Razor Views?

Junior

Answer

Razor Views are templates that combine HTML with C# using the Razor syntax to render dynamic HTML responses.

Razor is lightweight, fast, and avoids the heavy view state and page lifecycle of WebForms. Views are usually driven by strongly typed models, enabling clean separation of concerns between UI and logic.

Quick Summary: Razor Views are .cshtml files that combine HTML markup with C# code to generate dynamic HTML responses. They use the Razor syntax (@Model.Name, @foreach, @if) to embed C# expressions. The view gets a strongly-typed Model from the controller, making it type-safe. The Razor compiler converts .cshtml to C# classes at build or runtime.
Q2:

Explain Layouts, Partial Views, and View Components.

Junior

Answer

Layouts define a shared page shell (e.g., header, footer, navigation) used across many views.

Partial Views are reusable view fragments for rendering common UI pieces (e.g., a login panel or a list of items).

View Components encapsulate both rendering logic and view; they behave like mini-controllers plus views and are ideal for widgets (menus, dashboards, notifications) that need their own logic and markup.

Quick Summary: Layout: the shared template (_Layout.cshtml) that wraps all views — navigation, header, footer, common CSS/JS. Partial View: a reusable fragment rendered inside a view (like a product card). View Component: like a mini-controller+view — has its own logic, can query the database, and renders independently. More powerful than Partial Views for complex UI pieces.
Q3:

What are Tag Helpers?

Junior

Answer

Tag Helpers let you apply server-side behavior to HTML elements using natural HTML syntax.

Examples include form, input, link, and environment helpers. They integrate tightly with routing, model binding, and validation, improving readability and tooling support (IntelliSense) compared to traditional HTML helpers.

Quick Summary: Tag Helpers are C# classes that transform HTML elements in Razor views — they look like HTML attributes but are processed server-side. Home generates the correct URL automatically. They're more IDE-friendly and readable than HTML Helpers (@Html.ActionLink()), and support IntelliSense and validation.
Q4:

What is TempData and how is it different from ViewData/ViewBag?

Junior

Answer

ViewData and ViewBag are used to pass data from controllers to views within the same request.

  • ViewData is a Dictionary<string, object>.
  • ViewBag is a dynamic wrapper around ViewData.

TempData persists data across a single redirect and is cleared once read. It is backed by cookies or session and is ideal for messages (e.g., success notifications) that survive a redirect.

Quick Summary: TempData persists for one redirect cycle — you set it before a redirect and read it after. Useful for flash messages ("Record saved!"). ViewData is a dictionary passed from controller to view within one request. ViewBag is dynamic wrapper over ViewData. TempData uses session or cookies behind the scenes; ViewData and ViewBag don't survive redirects.
Q5:

What is Anti-Forgery and why is it required?

Junior

Answer

Anti-forgery protection defends against Cross-Site Request Forgery (CSRF) attacks.

ASP.NET Core generates a pair of correlated tokens: one stored in a cookie and one embedded in the form. On POST, both must be present and valid. This ensures that state-changing requests originate from the legitimate site and user, not from a malicious third-party page.

Quick Summary: Anti-Forgery tokens prevent Cross-Site Request Forgery (CSRF) attacks where a malicious site tricks a user's browser into submitting a form to your app. ASP.NET Core generates a hidden form token and a cookie token. On form submission, it verifies both match. The [ValidateAntiForgeryToken] attribute or Razor form tag helpers handle this automatically.
Q6:

How does ASP.NET Core handle static files and why is the middleware special?

Junior

Answer

Static files (CSS, JavaScript, images, etc.) are served by the Static File Middleware, which is usually placed early in the pipeline.

When a request matches a static file in wwwroot (or another configured folder), the middleware serves it directly and short-circuits the pipeline, bypassing MVC and other components. This leads to better performance and avoids unnecessary computation for simple file requests.

Quick Summary: The Static Files middleware serves files from wwwroot directly — HTML, CSS, JS, images — without going through MVC routing. It must be placed before UseRouting() and UseAuthentication() or it would require authentication to serve a CSS file. It short-circuits the pipeline for matching static files, returning them directly without controller processing.
Q7:

What is the difference between the Generic Host and Web Host in ASP.NET Core?

Junior

Answer

Earlier ASP.NET Core versions used WebHost to configure web-specific hosting (Kestrel, IIS integration, MVC, etc.).

The newer Generic Host unifies hosting for all app types (web, background services, workers, gRPC, SignalR) under a single abstraction.

  • Generic Host centralizes DI, configuration, and logging.
  • It supports non-web workloads and multiple hosted services in the same process.
  • For web apps, Generic Host wires in WebHost-like features such as Kestrel and endpoint routing under the hood.
Quick Summary: Web Host (IWebHostBuilder) was the original ASP.NET Core host — web-specific, tied to HTTP. Generic Host (IHostBuilder) is the modern replacement — it supports web, workers, console apps, and Windows services all with the same pattern. Generic Host is recommended for all new apps; Web Host is legacy. WebApplication builder (.NET 6+) wraps Generic Host.
Q8:

Explain the Application Lifetime events in ASP.NET Core (IHostApplicationLifetime).

Junior

Answer

IHostApplicationLifetime (renamed to IHostApplicationLifetime / IHostApplicationLifetime in newer versions) exposes three key notifications:

  • ApplicationStarted – Fired when the app is fully started and ready to serve requests.
  • ApplicationStopping – Fired when the app begins a graceful shutdown (e.g., SIGTERM in containers).
  • ApplicationStopped – Fired when shutdown is complete and cleanup has finished.

These events are used to warm up caches, start or stop background tasks, flush logs, and release resources in cloud and container environments.

Quick Summary: IHostApplicationLifetime provides three events: ApplicationStarted (app is fully started), ApplicationStopping (shutdown triggered, still running), ApplicationStopped (shutdown complete). Use these to run startup logic (warm caches) or cleanup (flush logs, close connections). Inject IHostApplicationLifetime wherever you need lifecycle hooks.
Q9:

What is the purpose of the Web Root and why is it separated from the Content Root?

Junior

Answer

The Content Root is the base path for application code, views, and configuration files.

The Web Root (usually wwwroot) is the publicly exposed folder for static files such as CSS, JS, and images.

Separating them ensures that sensitive assets like configuration files, views, and binaries are not accidentally served over HTTP. Only files under Web Root are directly reachable by clients.

Quick Summary: Content Root is the base directory of the application — where appsettings.json, views, and application files live. Web Root (wwwroot) is the subdirectory served as static files to browsers. The separation means the app can serve only the intentional public directory without exposing source files, config, or dlls to browsers.
Q10:

Explain the difference between Use, Run, and Map in middleware configuration.

Junior

Answer

  • Use – Adds middleware that can process the request and optionally call the next middleware via a next delegate.
  • Run – Adds terminal middleware that does not call the next component; it ends the pipeline.
  • Map – Branches the pipeline based on the request path, creating sub-pipelines for specific URL segments.

Together, they give fine-grained control over the shape and branching of the request pipeline.

Quick Summary: Use(): adds middleware that can call next — used for middleware that performs work and continues the pipeline. Run(): terminal middleware — never calls next, short-circuits the pipeline. Map(): branches the pipeline based on a URL prefix — creates a sub-pipeline for that branch. Use is the most common; Run ends the pipeline; Map enables path-based branching.
Q11:

What is Environment-based configuration and why is it essential?

Junior

Answer

ASP.NET Core supports named environments such as Development, Staging, and Production, typically controlled by the ASPNETCORE_ENVIRONMENT variable.

Environment controls:

  • Which configuration files are loaded (e.g., appsettings.Development.json).
  • Whether detailed error pages are shown.
  • Which services or features are enabled (e.g., runtime compilation only in Development).

Environment-based configuration prevents debug info and dev-only behaviors from leaking into production.

Quick Summary: ASPNETCORE_ENVIRONMENT (Development, Staging, Production) controls which appsettings.{env}.json file loads, enables/disables developer exception pages, and controls logging verbosity. IWebHostEnvironment.IsDevelopment() lets code behave differently per environment. Essential for showing detailed errors in dev and hiding them in production.
Q12:

What are Secrets in ASP.NET Core, and how are they different from configuration files?

Junior

Answer

User Secrets are a development-only feature for storing sensitive values (API keys, connection strings) outside the project tree.

  • They are not checked into source control.
  • They are only used for the Development environment.
  • They override configuration from JSON files.

In production, secrets should come from environment variables, Azure Key Vault, or similar secure stores, not from JSON configuration files.

Quick Summary: Secrets (User Secrets in dev, Azure Key Vault in production) store sensitive values (connection strings, API keys) outside appsettings.json so they're never committed to source control. In development, dotnet user-secrets stores them in a local JSON file outside the project. In production, inject them via environment variables or a secrets manager.
Q13:

Explain the Options Pattern and why it’s preferred over directly reading from configuration.

Junior

Answer

The Options Pattern binds configuration sections to strongly typed classes and injects them via IOptions<T>, IOptionsSnapshot<T>, or IOptionsMonitor<T>.

Benefits include:

  • Centralized configuration mapping and validation.
  • No magic strings scattered throughout the code.
  • Ability to reload or react to config changes.
  • Cleaner separation of configuration from business logic.
Quick Summary: The Options Pattern binds a configuration section to a strongly-typed class (services.Configure(config.GetSection("MySection"))). You inject IOptions and access typed properties instead of error-prone string keys. Supports validation, change tracking, and makes configuration testable and refactorable with compile-time safety.
Q14:

What is Razor View Compilation and why does it matter?

Junior

Answer

Razor View Compilation converts .cshtml files into C# classes and compiles them into assemblies.

  • Runtime compilation – Views are compiled on first use; flexible but slower for initial requests.
  • Precompilation – Views are compiled at build/publish time; improves startup and reduces CPU at runtime.

Production apps typically use precompiled views to improve startup time and performance.

Quick Summary: In .NET 6+, Razor views are compiled at publish time by default — no .cshtml files are needed in production, and no runtime compilation happens. This improves startup performance and deployment simplicity. In development, runtime compilation is enabled via Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation so changes are picked up without rebuild.
Q15:

What is the View Engine and how does Razor differ from classic engines?

Junior

Answer

The View Engine is responsible for locating and rendering views from templates.

Razor differs from older engines by:

  • Using C# instead of server controls or code-behind pages.
  • Eliminating view state and page lifecycle complexity.
  • Producing clean HTML with async support.
  • Providing strong tooling and compile-time checks.
Quick Summary: The Razor view engine compiles .cshtml files to C# classes that inherit RazorPage. The Execute() method generates the HTML. The engine resolves views by convention (/Views/{Controller}/{Action}.cshtml). Multiple engines can coexist — ASP.NET Core supports registering custom view engines alongside Razor.
Q16:

What are Tag Helper Scopes and how do they improve structure?

Junior

Answer

Tag Helpers operate within the HTML element tree and can apply behavior to all nested content.

Scoped helpers like <environment> wrap child elements to conditionally render sets of tags based on environment, reducing duplication and improving structure.

They help apply consistent behavior (e.g., script loading, validation attributes) across entire sections of the UI.

Quick Summary: Tag Helper scope is controlled by @addTagHelper and @removeTagHelper directives in _ViewImports.cshtml. You can add tag helpers globally (for the whole app) or restrict them to specific namespaces and assemblies. This prevents conflicts when two tag helpers process the same HTML element and lets teams control which tag helpers are available in which views.
Q17:

What is ViewData, ViewBag, and TempData?

Junior

Answer

  • ViewData – A Dictionary<string, object> for passing data from controller to view in the same request.
  • ViewBag – A dynamic wrapper around ViewData for more convenient syntax.
  • TempData – Persists data across one redirect; cleared after it is read.

ViewData/ViewBag are for same-request communication; TempData is designed for redirect scenarios such as Post-Redirect-Get.

Quick Summary: ViewData: dictionary, requires casting when reading, ViewData["Title"] = "Home". ViewBag: dynamic wrapper over ViewData — ViewBag.Title = "Home". TempData: survives a redirect — stored in cookie or session. All three pass data from controller to view within a request. ViewData and ViewBag are equivalent; TempData is the only one that persists across redirects.
Q18:

Explain Endpoint Routing in detail.

Junior

Answer

Endpoint Routing decouples route matching from endpoint execution.

  • UseRouting() runs early, matches the request to an endpoint, and attaches endpoint metadata.
  • Middleware such as authentication and authorization can inspect endpoint metadata.
  • UseEndpoints() executes the matched endpoint (controller, Razor Page, minimal API).

This improves performance, centralizes routing, and makes it easier to apply policies based on endpoint metadata.

Quick Summary: Endpoint Routing separates route matching from execution. UseRouting() matches the request to an endpoint and stores it in HttpContext. UseAuthorization() can then check the matched endpoint's metadata (including auth requirements) before execution. UseEndpoints() executes the matched endpoint. This separation allows middleware to inspect the matched route before execution.
Q19:

What is Model Binding Value Providers?

Junior

Answer

Value Providers are components in the model binding system that know how to fetch data from specific sources:

  • Route values
  • Query strings
  • Form data
  • Headers
  • Cookies

Model binding queries these providers in order to construct complex models from the incoming HTTP request.

Quick Summary: Model Binding uses Value Providers to read data from different parts of the request. Built-in providers: FormValueProvider (form data), RouteValueProvider (route segments), QueryStringValueProvider (query string), HeaderValueProvider, and BodyValueProvider (JSON/XML body). Custom Value Providers let you read from cookies, services, or any custom source.
Q20:

Explain Custom Model Binding and when it is required.

Junior

Answer

Custom Model Binding is used when default binding cannot map request data to models correctly.

Typical use cases:

  • Non-standard data formats.
  • Combining multiple values into a single complex object.
  • Parsing custom header or route patterns.

Implementing IModelBinder or using custom attributes provides full control over how request data is translated into .NET types.

Quick Summary: Custom Model Binders handle types that the default binder can't bind — enums from string aliases, comma-separated lists to arrays, complex query parameter formats, or binding from non-standard locations. Implement IModelBinder, return the constructed object, and register it with ModelBinderProviders in MVC options.

Curated Sets for .NET Core

No curated sets yet. Group questions into collections from the admin panel to feature them here.

Ready to level up? Start Practice