DotNet Coding Specialist (DCS) — ASP.NET Core — Questions and Answers
Question 1: Which service lifetime registers a new instance for every HTTP request in ASP.NET Core?
- Singleton
- PerRequest
- Transient
- Scoped (Correct answer)
Correct answer: Scoped
Scoped services are created once per HTTP request and shared within that request's scope.
Question 2: What does the Logging:LogLevel:Default configuration key control?
- The default log provider to use
- The minimum log level for all categories that don't have a specific override (Correct answer)
- The maximum number of log entries stored
- The output format of log messages
Correct answer: The minimum log level for all categories that don't have a specific override
Logging:LogLevel:Default sets the baseline minimum severity; categories with specific entries override this default.
Question 3: Which CLI command initializes User Secrets for an ASP.NET Core project?
- dotnet user-secrets init (Correct answer)
- dotnet init secrets
- dotnet secret init
- dotnet secrets create
Correct answer: dotnet user-secrets init
dotnet user-secrets init adds a UserSecretsId GUID to the project file and sets up the local secrets store.
Question 4: Which file is the primary configuration source in an ASP.NET Core application?
- settings.json
- config.json
- appsettings.json (Correct answer)
- web.config
Correct answer: appsettings.json
appsettings.json is the default configuration file read by the ASP.NET Core host, with environment-specific overrides supported.
Question 5: What does the ASPNETCORE_ENVIRONMENT environment variable control?
- The base URL of the application
- The log output destination
- The active environment name, affecting which appsettings and middleware are loaded (Correct answer)
- The port the Kestrel server listens on
Correct answer: The active environment name, affecting which appsettings and middleware are loaded
ASPNETCORE_ENVIRONMENT sets IWebHostEnvironment.EnvironmentName, switching between Development, Staging, and Production behaviors.
Question 6: What is the purpose of the ConfigureAppConfiguration method in the host builder?
- Sets the application's startup class
- Configures the application's DI container
- Configures logging providers
- Adds or customizes configuration sources for the application (Correct answer)
Correct answer: Adds or customizes configuration sources for the application
ConfigureAppConfiguration allows adding or modifying configuration providers such as JSON files, environment variables, or custom sources.
Question 7: Which EF Core method applies pending migrations to the database?
- dotnet ef database update (Correct answer)
- dotnet ef schema update
- dotnet ef migrations apply
- dotnet ef db migrate
Correct answer: dotnet ef database update
dotnet ef database update applies all pending migrations, creating or altering tables as defined in the migration files.
Question 8: In what order does ASP.NET Core execute middleware components?
- Alphabetically by class name
- In the order they are registered (Correct answer)
- Based on priority attribute
- In reverse order of registration
Correct answer: In the order they are registered
Middleware executes in the order it is registered in the Configure method or Program.cs.
Question 9: How do you inject multiple implementations of the same interface in ASP.NET Core DI?
- Inject IEnumerable<TService> in the constructor (Correct answer)
- Multiple implementations are not supported
- Use a factory method only
- Register them under different names
Correct answer: Inject IEnumerable<TService> in the constructor
ASP.NET Core DI resolves all registered implementations of an interface when IEnumerable<TService> is injected.
Question 10: Which of the following is the ASP.NET Core application's entry point?
- Application_start method of Global.asax
- Configure method of Startup class
- ConfigureService method of Startup class
- Main method of the Program class (Correct answer)
Correct answer: Main method of the Program class
Explanation: <br> The application's main() method is used to start it up. When we run an ASP.NET Core Web application, the first thing it does is seek for the Main() function, which is where the execution begins. ASP.NET Core is then configured and started using the Main() function. The app is now an ASP.NET Core web app.
Question 11: What method is called to add MVC controllers with views in ASP.NET Core?
- services.AddViewControllers()
- services.AddControllersWithViews() (Correct answer)
- services.AddMvc()
- services.AddControllers()
Correct answer: services.AddControllersWithViews()
AddControllersWithViews() registers controllers plus Razor view support, whereas AddControllers() registers controllers for APIs only.
Question 12: By default, an ASP.NET Core web application utilizes _____as an internal web server.
- Kestrel (Correct answer)
- IIS
- Apache
- nginx
Correct answer: Kestrel
Explanation: <br> Kestrel is a cross-platform web server that supports ASP.NET Core. It's compatible with all.NET Core platforms and versions. In ASP.NET Core, it comes preinstalled as an internal server. Kestrel can be used as an edge server, which is an Internet-facing web server that can process client HTTP requests directly. The program is hosted by the dotnet.exe process in Kestrel.
Question 13: What is a short-circuiting middleware?
- Middleware that runs asynchronously
- Middleware that throws an exception
- Middleware that does not call next(), ending the pipeline (Correct answer)
- Middleware that calls next() twice
Correct answer: Middleware that does not call next(), ending the pipeline
A short-circuiting middleware returns a response without calling next(), preventing further middleware from executing.
Question 14: What is the purpose of app.Run() in the middleware pipeline?
- Adds a terminal middleware that never calls next() (Correct answer)
- Registers background services
- Starts the web host
- Runs the application
Correct answer: Adds a terminal middleware that never calls next()
app.Run() adds a terminal middleware delegate that handles requests without forwarding to any subsequent middleware.
Question 15: Which attribute defines a route template directly on an ASP.NET Core controller action?
- [Path]
- [HttpGet]
- [Endpoint]
- [Route] (Correct answer)
Correct answer: [Route]
[Route("path")] sets the route template for a controller or action, and can be combined with HTTP method attributes.
Question 16: Which mechanisms can pass data from a Razor Pages PageModel to its view beyond the strongly-typed Model property?
- ViewBag only
- ViewData only
- ViewData, ViewBag, and TempData are all valid options (Correct answer)
- TempData only
Correct answer: ViewData, ViewBag, and TempData are all valid options
ViewData (dictionary), ViewBag (dynamic wrapper over ViewData), and TempData all provide ways to pass data from a PageModel to its view.
Question 17: What method is used to add middleware to the ASP.NET Core request pipeline?
- app.MapMiddleware()
- app.RegisterMiddleware()
- app.AddMiddleware()
- app.UseMiddleware() (Correct answer)
Correct answer: app.UseMiddleware()
app.UseMiddleware<T>() is the standard method to add custom middleware to the ASP.NET Core pipeline.
Question 18: What is the purpose of the 'next' delegate in ASP.NET Core middleware?
- To log the request
- To return a response immediately
- To call the next middleware in the pipeline (Correct answer)
- To authenticate the user
Correct answer: To call the next middleware in the pipeline
Calling next(context) passes control to the subsequent middleware component in the pipeline.
Question 19: Which file is conventionally used to set a default layout for all Razor views in a folder and its subfolders?
- _Layout.cshtml
- _ViewImports.cshtml
- _ViewStart.cshtml (Correct answer)
- _Default.cshtml
Correct answer: _ViewStart.cshtml
_ViewStart.cshtml executes before any view in the same folder and is typically used to set the Layout property globally.
Question 20: In which environment is UseDeveloperExceptionPage() typically called?
- Development (Correct answer)
- Staging
- All environments
- Production
Correct answer: Development
UseDeveloperExceptionPage() shows detailed error info and should only be used in Development to avoid leaking sensitive data.
Question 21: What happens when middleware adds to HttpContext.Items?
- Data is saved to session
- Data is shared across all users
- Data persists across requests
- Data is shared only for the lifetime of the current request (Correct answer)
Correct answer: Data is shared only for the lifetime of the current request
HttpContext.Items is a dictionary scoped to the current request, allowing middleware and handlers to share data within a single request.
Question 22: What interface is used to access the DI service container manually in ASP.NET Core?
- IServiceContainer
- IDependencyResolver
- IServiceLocator
- IServiceProvider (Correct answer)
Correct answer: IServiceProvider
IServiceProvider exposes the GetService and GetRequiredService methods to resolve dependencies from the container.
Question 23: Which middleware must be added before UseAuthorization() for authentication to work?
- UseJwt()
- UseLogin()
- UseIdentity()
- UseAuthentication() (Correct answer)
Correct answer: UseAuthentication()
UseAuthentication() must precede UseAuthorization() so that user identity is established before authorization policies are evaluated.
Question 24: What happens when you call builder.Configuration.AddJsonFile("custom.json", optional: false, reloadOnChange: true)?
- Only loads if the file exists, ignores missing files
- Replaces all existing configuration
- Loads the file once and never reloads
- Throws if the file doesn't exist and watches for file changes to reload config (Correct answer)
Correct answer: Throws if the file doesn't exist and watches for file changes to reload config
optional: false throws an exception if the file is missing, and reloadOnChange: true watches the file for changes and reloads configuration automatically.
Question 25: What is constructor injection in ASP.NET Core DI?
- Manually creating service instances in constructors
- Declaring dependencies as constructor parameters that the DI container resolves automatically (Correct answer)
- Using [Inject] attributes on constructors
- Injecting configuration into constructors only
Correct answer: Declaring dependencies as constructor parameters that the DI container resolves automatically
Constructor injection is the primary DI pattern where ASP.NET Core resolves and passes dependencies automatically when creating the class.
Question 26: What is the purpose of IConfiguration.GetConnectionString("name") in ASP.NET Core?
- It creates a database connection
- It reads connection strings from environment variables only
- It validates the connection string format
- It retrieves the connection string from the ConnectionStrings section by name (Correct answer)
Correct answer: It retrieves the connection string from the ConnectionStrings section by name
GetConnectionString() is a shorthand for configuration.GetSection("ConnectionStrings")[name], a conventional location for connection strings.
Question 27: What does [Authorize(Policy = "MinimumAge")] require in ASP.NET Core?
- An age filter attribute
- A role named MinimumAge in the database
- A MinimumAge claim in the user's JWT token
- A named policy 'MinimumAge' to be registered with requirements in AddAuthorization() (Correct answer)
Correct answer: A named policy 'MinimumAge' to be registered with requirements in AddAuthorization()
Policy-based authorization evaluates the named policy's requirements, which must be registered during application startup.
Question 28: What does UseHsts() middleware do?
- Compresses responses
- Forces HTTPS redirects
- Adds HTTP Strict Transport Security headers (Correct answer)
- Enables HTTP/2
Correct answer: Adds HTTP Strict Transport Security headers
UseHsts() adds the Strict-Transport-Security response header, instructing browsers to only connect via HTTPS.
Question 29: Which of the following can be targeted by ASP.NET Core applications?
- .NET Standard
- .NET Framework 4x
- .NET Core
- All of the above (Correct answer)
Correct answer: All of the above
Explanation: <br> Frameworks that target ASP.NET Core. Only.NET Core can be targeted by ASP.NET Core 3.x and later. ASP.NET Core is primarily made up of.NET Standard libraries. Any.NET platform that implements.NET Standard 2.0 can run libraries written with.NET Standard 2.0.
Question 30: Which EF Core loading strategy fetches related entities in the same query using a JOIN?
- Deferred loading
- Eager loading with Include() (Correct answer)
- Lazy loading
- Explicit loading with Load()
Correct answer: Eager loading with Include()
Eager loading via Include() fetches related entities in a single SQL query using JOINs, avoiding the N+1 query problem.
Question 31: What route token represents an action name in a conventional route template?
- [action]
- <action>
- {action} (Correct answer)
- $(action)
Correct answer: {action}
{action} is the conventional route token that maps to the action method name in the default MVC route template.
Question 32: Which handler class must be extended to implement a custom authorization requirement handler?
- RequirementHandler<T>
- AuthorizationHandler<TRequirement> (Correct answer)
- ClaimsAuthorizationHandler
- PolicyHandler<TRequirement>
Correct answer: AuthorizationHandler<TRequirement>
Custom handlers inherit from AuthorizationHandler<TRequirement> and implement HandleRequirementAsync() to evaluate the requirement.
Question 33: What is the role of the IApplicationBuilder interface in ASP.NET Core?
- It registers services in the DI container
- It manages database connections
- It defines application settings
- It configures the request processing pipeline (Correct answer)
Correct answer: It configures the request processing pipeline
IApplicationBuilder provides methods like Use, Run, and Map to compose the middleware pipeline.
Question 34: What attribute enables property injection in ASP.NET Core Razor Pages?
- [FromServices] (Correct answer)
- [AutoInject]
- [Inject]
- [BindProperty]
Correct answer: [FromServices]
[FromServices] on a parameter or property tells the framework to resolve the value from the DI container rather than from the request.
Question 35: The ASP.NET core web application's host is set up in the________ file.
- None of the these
- Startup.cs
- Program.cs (Correct answer)
- Middleware
Correct answer: Program.cs
Explanation: <br> The application begins at Program.cs. The Program.cs file will behave similarly to the Program.cs file in a traditional.NET Framework console application. The Program.cs file is the application's entry point, and it will be responsible for registering Startup.cs, IISIntegration, and the Main method's Create a host using an instance of IWebHostBuilder.
DotNet Coding Specialist (DCS) — ASP.NET Core
The DotNet Coding Specialist certification validates hands-on .NET application development skills including ASP.NET Core middleware, dependency injection, authentication, configuration, and web API design using live-in-the-app question formats.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds