Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 5 MCQsASP.NET Core MVC, Entity Framework Core and Security
Question 1 of 60 · Middleware Request Pipeline · Easy
What is the main purpose of the middleware request pipeline in ASP.NET Core?
Not quite. Try another option.
Answer: To process HTTP requests and responses
The middleware request pipeline processes HTTP requests and responses through a sequence of configured components.
Question 2 of 60 · Middleware Request Pipeline · Easy
In an ASP.NET Core application, middleware components are generally executed in what order?
Not quite. Try another option.
Answer: The order in which they are registered
Middleware runs in the order it is added to the application pipeline.
Question 3 of 60 · Built-In Middleware and Custom Middleware · Easy
Which middleware is commonly used to serve static files in ASP.NET Core?
Not quite. Try another option.
Answer: Static File Middleware
Static File Middleware serves files such as CSS, JavaScript, and images from the web root.
Question 4 of 60 · Built-In Middleware and Custom Middleware · Easy
What is custom middleware?
Not quite. Try another option.
Answer: Middleware written for a specific application need
Custom middleware is developer-created code that handles a particular request or response task.
Question 5 of 60 · Dependency Injection in ASP.NET Core · Easy
What is the main purpose of dependency injection in ASP.NET Core?
Not quite. Try another option.
Answer: To provide required objects to classes
Dependency injection supplies a class with the services or objects it needs instead of requiring the class to create them.
Question 6 of 60 · Dependency Injection in ASP.NET Core · Easy
Where are application services commonly registered for dependency injection?
Not quite. Try another option.
Answer: In the application service container
Services are registered in ASP.NET Core's built-in dependency injection service container.
Question 7 of 60 · Introduction to Entity Framework Core · Easy
What is Entity Framework Core primarily used for?
Not quite. Try another option.
Answer: Working with databases through .NET objects
Entity Framework Core is an object-relational mapper that allows applications to work with databases using .NET objects.
Question 8 of 60 · Introduction to Entity Framework Core · Easy
What does ORM stand for?
Not quite. Try another option.
Answer: Object-Relational Mapper
ORM stands for Object-Relational Mapper, a tool that maps programming objects to relational database data.
Question 9 of 60 · DbContext and Entity Configuration · Easy
What is the role of the DbContext class in Entity Framework Core?
Not quite. Try another option.
Answer: It manages database interaction and entity tracking
DbContext provides access to database sets and tracks changes made to entities.
Question 10 of 60 · DbContext and Entity Configuration · Easy
Which property type in a DbContext usually represents a database table?
Not quite. Try another option.
Answer: DbSet<TEntity>
A DbSet<TEntity> represents a collection of entities that can be queried and stored in a database table.
Question 11 of 60 · Code First Approach · Easy
What is created first in the Entity Framework Core Code First approach?
Not quite. Try another option.
Answer: The application classes and model
In Code First, developers define entity classes and use them to create or update the database structure.
Question 12 of 60 · Code First Approach · Easy
Which feature is commonly used to apply Code First model changes to a database?
Not quite. Try another option.
Answer: Entity Framework migrations
Entity Framework migrations record model changes and apply those changes to the database.
Question 13 of 60 · Database First Approach · Easy
What is the starting point in the Database First approach?
Not quite. Try another option.
Answer: An existing database
Database First begins with an existing database, from which entity classes and context code can be generated.
Question 14 of 60 · Database First Approach · Easy
What is commonly generated from an existing database in the Database First approach?
Not quite. Try another option.
Answer: Entity classes and a DbContext
Database First tools generate entity classes and a DbContext that represent the existing database.
Question 15 of 60 · Database Migrations · Easy
What is the purpose of a database migration in Entity Framework Core?
Not quite. Try another option.
Answer: To record and apply model structure changes
Migrations describe changes to the model and update the database schema accordingly.
Question 16 of 60 · Database Migrations · Easy
Which command is commonly used to create a new Entity Framework Core migration?
Not quite. Try another option.
Answer: dotnet ef migrations add
The dotnet ef migrations add command creates a migration based on changes in the entity model.
Question 17 of 60 · CRUD Operations using Entity Framework Core · Easy
What does the letter C represent in CRUD?
Not quite. Try another option.
Answer: Create
CRUD stands for Create, Read, Update, and Delete.
Question 18 of 60 · CRUD Operations using Entity Framework Core · Easy
Which method marks a new entity for insertion into the database?
Not quite. Try another option.
Answer: Add
The Add method marks a new entity for insertion when changes are saved.
Question 19 of 60 · Authentication and Authorization in Web Applications · Easy
What does authentication verify?
Not quite. Try another option.
Answer: The identity of a user
Authentication verifies who a user is, usually by checking credentials or an identity token.
Question 20 of 60 · Authentication and Authorization in Web Applications · Easy
What does authorization determine?
Not quite. Try another option.
Answer: What an authenticated user may access
Authorization determines whether a user has permission to access a resource or perform an action.
Question 21 of 60 · Middleware Request Pipeline · Medium
An ASP.NET Core application must log both the incoming request and the outgoing response status. Where should the logging middleware call await next(context)?
Not quite. Try another option.
Answer: Between the request log and the response log
Code before await next(context) runs while the request travels forward, and code after it runs as the response travels back.
Question 22 of 60 · Middleware Request Pipeline · Medium
A middleware component returns a response without invoking the next middleware. What is the effect on the request pipeline?
Not quite. Try another option.
Answer: The remaining middleware components are skipped
Not calling the next delegate short-circuits the pipeline, so later middleware components do not process the request.
Question 23 of 60 · Built-In Middleware and Custom Middleware · Medium
An application should serve files from wwwroot without routing those requests through MVC controllers. Which built-in middleware should be added?
Not quite. Try another option.
Answer: app.UseStaticFiles()
UseStaticFiles serves files from the configured web root and can handle matching requests before they reach MVC endpoints.
Question 24 of 60 · Built-In Middleware and Custom Middleware · Medium
A conventional custom middleware class receives a RequestDelegate through its constructor. Which method signature allows ASP.NET Core to execute it?
Not quite. Try another option.
Answer: Task InvokeAsync(HttpContext context)
Convention-based middleware exposes an Invoke or InvokeAsync method that accepts HttpContext and returns Task.
Question 25 of 60 · Dependency Injection in ASP.NET Core · Medium
A service stores information that must be shared within one HTTP request but isolated from other requests. Which lifetime should be used?
Not quite. Try another option.
Answer: Scoped
A scoped service is created once per HTTP request and reused within that request.
Question 26 of 60 · Dependency Injection in ASP.NET Core · Medium
A controller constructor requires IEmailSender, but no implementation has been registered. What normally happens when ASP.NET Core tries to create the controller?
Not quite. Try another option.
Answer: Service resolution throws an exception
Constructor dependencies must be resolvable from the service container; otherwise, controller activation fails with an exception.
Question 27 of 60 · Introduction to Entity Framework Core · Medium
A queried entity is modified in memory and SaveChangesAsync() is called without explicitly calling Update. Why can Entity Framework Core persist the modification?
Not quite. Try another option.
Answer: The change tracker detects modified property values
Tracked entities have their state and values monitored, allowing EF Core to generate an appropriate update during SaveChangesAsync().
Question 28 of 60 · Introduction to Entity Framework Core · Medium
The same EF Core model must run against SQL Server in production and SQLite during local testing. Which EF Core feature primarily enables this?
Not quite. Try another option.
Answer: Replaceable database providers
EF Core uses provider packages that translate model operations and LINQ queries for a particular database system.
Question 29 of 60 · DbContext and Entity Configuration · Medium
A Blog has many Post entities, and every Post has one required Blog. Which Fluent API configuration best represents this relationship?
HasMany and WithOne configure the one-to-many relationship, while IsRequired makes the dependent relationship mandatory.
Question 30 of 60 · DbContext and Entity Configuration · Medium
An entity property must map to a database column named product_code and have a maximum length of 20. Where can both rules be configured centrally?
Not quite. Try another option.
Answer: In OnModelCreating using the Fluent API
OnModelCreating provides centralized model configuration through methods such as HasColumnName and HasMaxLength.
Question 31 of 60 · Code First Approach · Medium
In a Code First project, a developer adds a required Email property to the Customer entity. What should normally be done to apply this model change to the database?
Not quite. Try another option.
Answer: Create a migration and update the database
Code First migrations capture model changes and translate them into database schema operations.
Question 32 of 60 · Code First Approach · Medium
A Code First model uses a property named CustomerId in the Customer class without explicit key configuration. How does EF Core usually treat this property?
Not quite. Try another option.
Answer: As the primary key by convention
EF Core recognizes properties named Id or <EntityName>Id as primary keys by convention.
Question 33 of 60 · Database First Approach · Medium
A team has an existing SQL Server database and needs to generate EF Core entity classes and a DbContext. Which command is appropriate?
Not quite. Try another option.
Answer: dotnet ef dbcontext scaffold
dotnet ef dbcontext scaffold reverse-engineers an existing database into entity classes and a context.
Question 34 of 60 · Database First Approach · Medium
A developer needs to add custom behavior to a scaffolded entity while allowing the entity to be regenerated later. Which approach best protects the custom code?
Not quite. Try another option.
Answer: Add the behavior in a separate partial class
A separate partial class extends the generated type without placing custom code in files that may be overwritten during rescaffolding.
Question 35 of 60 · Database Migrations · Medium
A migration has been created locally but has not been applied or shared. The developer discovers that it is incorrect. Which command is most appropriate for removing it?
Not quite. Try another option.
Answer: dotnet ef migrations remove
migrations remove deletes the latest unapplied migration and updates the model snapshot accordingly.
Question 36 of 60 · Database Migrations · Medium
A production administrator needs a reviewable SQL script containing database changes between two migrations. Which command should the developer use?
Not quite. Try another option.
Answer: dotnet ef migrations script
migrations script generates SQL for a migration range, allowing the changes to be reviewed and deployed separately.
Question 37 of 60 · CRUD Operations using Entity Framework Core · Medium
A read-only product listing loads thousands of rows and does not modify them. Which query is generally more efficient?
AsNoTracking avoids change-tracking overhead when the returned entities are only being read.
Question 38 of 60 · CRUD Operations using Entity Framework Core · Medium
A controller must delete an order only when it exists. Which sequence correctly performs the operation?
Not quite. Try another option.
Answer: Find the order, call Remove, then call SaveChangesAsync
The entity should first be located, marked as deleted with Remove, and then persisted by calling SaveChangesAsync.
Question 39 of 60 · Authentication and Authorization in Web Applications · Medium
An ASP.NET Core application uses cookie authentication and protected endpoints. Which middleware order is required after routing and before endpoint execution?
Not quite. Try another option.
Answer: UseAuthentication() followed by UseAuthorization()
Authentication must first establish the user's identity so authorization can evaluate that user against endpoint requirements.
Question 40 of 60 · Authentication and Authorization in Web Applications · Medium
An action should be accessible only to authenticated users who satisfy a policy named CanApproveOrders. Which attribute is appropriate?
Not quite. Try another option.
Answer: [Authorize(Policy = "CanApproveOrders")]
The Policy property of AuthorizeAttribute applies the named authorization policy to the action or controller.
Question 41 of 60 · Middleware Request Pipeline · Hard
In an ASP.NET Core application, middleware is registered in this order: UseExceptionHandler, UseStaticFiles, UseRouting, UseAuthentication, UseAuthorization, and MapControllers. A controller throws an exception while executing an authorized action. Which component can reliably handle the exception?
Not quite. Try another option.
Answer: UseExceptionHandler
UseExceptionHandler is registered before the downstream components, so its surrounding request delegate can catch unhandled exceptions generated later in the pipeline.
Question 42 of 60 · Middleware Request Pipeline · Hard
A middleware executes code before and after await _next(context). A later middleware short-circuits the request and never calls its own next delegate. Which behavior is expected?
Not quite. Try another option.
Answer: The current before-code and after-code both execute
The current middleware resumes after await _next(context) completes, even when a downstream component terminates the pipeline without invoking its next delegate.
Question 43 of 60 · Built-In Middleware and Custom Middleware · Hard
A custom middleware needs to redirect unauthenticated requests to /login, but must allow static assets and the login endpoint through. Which placement is most appropriate?
Not quite. Try another option.
Answer: After UseStaticFiles and before endpoint execution
Placing the middleware after static-file handling avoids protecting assets and placing it before endpoint execution allows it to inspect authentication and redirect application requests.
Question 44 of 60 · Built-In Middleware and Custom Middleware · Hard
A custom middleware stores a request-specific correlation identifier in an instance field of the middleware class. Under concurrent requests, what is the primary defect?
Not quite. Try another option.
Answer: The field may be overwritten by another request
Middleware instances are commonly created once and reused. Request-specific data must be stored in local variables, HttpContext, or an appropriately scoped service rather than instance fields.
Question 45 of 60 · Dependency Injection in ASP.NET Core · Hard
A singleton service directly depends on a scoped DbContext. What is the correct assessment of this dependency graph?
Not quite. Try another option.
Answer: It is invalid because a singleton captures a shorter-lived dependency
A singleton can outlive the scoped service and may retain it across requests. ASP.NET Core commonly detects this captive-dependency error during service validation.
Question 46 of 60 · Dependency Injection in ASP.NET Core · Hard
A controller constructor requests IEnumerable<INotificationHandler>. Three handlers are registered, and one registration is repeated for the same implementation type. What does the default container normally inject?
Not quite. Try another option.
Answer: All registered descriptors in registration order
The default container resolves IEnumerable<T> using all matching registrations, preserving their registration order, including repeated descriptors.
Question 47 of 60 · Introduction to Entity Framework Core · Hard
An EF Core query projects entities into DTOs and uses AsNoTracking(). Later, the application modifies one projected DTO and calls SaveChanges(). What happens?
Not quite. Try another option.
Answer: No update occurs unless an entity is explicitly attached
DTO projections are not entity instances managed for persistence, and AsNoTracking() disables tracking. An entity must be loaded or attached and marked appropriately before updating.
Question 48 of 60 · Introduction to Entity Framework Core · Hard
A LINQ query contains a custom C# method inside its Where predicate. EF Core cannot translate that method to SQL. In a modern EF Core version, what is the usual result when the query executes?
Not quite. Try another option.
Answer: EF throws an exception for unsupported client evaluation
EF Core generally permits client evaluation only in the final projection. An untranslatable predicate typically causes a runtime translation exception rather than silent full-table evaluation.
Question 49 of 60 · DbContext and Entity Configuration · Hard
An entity has a property Code configured with IsRequired().HasMaxLength(20), while its database column is manually changed to allow NULL. During migration generation, what does EF Core compare?
Not quite. Try another option.
Answer: The model snapshot against the current model
Migrations are generated by comparing the current EF model with the stored model snapshot. EF does not normally inspect the live database schema to discover arbitrary manual changes.
Question 50 of 60 · DbContext and Entity Configuration · Hard
A required one-to-many relationship is configured with a non-nullable foreign key, but the navigation property is not marked virtual and lazy-loading proxies are enabled. What should be expected?
Not quite. Try another option.
Answer: Lazy loading does not occur for the non-virtual navigation
Proxy-based lazy loading requires eligible virtual navigation properties and suitable proxy configuration. Relationship requiredness does not make a non-virtual navigation lazy-loadable.
Question 51 of 60 · Code First Approach · Hard
A Code First model changes a property from string to int while existing rows contain nonnumeric values. A migration is generated successfully. When is the likely failure observed?
Not quite. Try another option.
Answer: When the migration is applied to the database
Migration scaffolding can describe the type change without validating existing data. The database conversion commonly fails when the generated ALTER COLUMN operation is executed.
Question 52 of 60 · Code First Approach · Hard
A Code First application uses a non-nullable DateTime property with no explicit database default. A new entity is inserted without setting that property. Which value is generally sent by EF Core?
Not quite. Try another option.
Answer: The CLR default value for DateTime
Without value-generation configuration or a database default, EF uses the value present on the entity. An unset non-nullable DateTime therefore has its CLR default.
Question 53 of 60 · Database First Approach · Hard
A database-first model is scaffolded, then the generated entity class is edited to add validation attributes. The database is scaffolded again. What is the main risk?
Not quite. Try another option.
Answer: The custom edits may be overwritten
Re-scaffolding can replace generated files. Custom behavior should generally be placed in partial classes, separate configurations, or other files excluded from regeneration.
Question 54 of 60 · Database First Approach · Hard
A database-first scaffold sees a nullable database column and generates a nullable CLR property. Application code later treats the value as non-nullable without checking it. Which issue is most likely?
Not quite. Try another option.
Answer: The compiler or runtime exposes a nullability mismatch
The scaffold reflects database nullability. Treating a nullable property as definitely non-null can produce compiler warnings or runtime failures depending on the access pattern.
Question 55 of 60 · Database Migrations · Hard
Two application instances start simultaneously after a new migration has been deployed but not applied. Both call Database.Migrate(). What is the principal operational concern?
Not quite. Try another option.
Answer: Concurrent migration execution can cause locking or race failures
Applying migrations during startup from multiple instances introduces deployment coordination and locking concerns. Migrations are usually applied through a controlled deployment process.
Question 56 of 60 · Database Migrations · Hard
A migration adds a non-nullable column to a populated table without a default value. What must usually be handled for the migration to succeed?
Not quite. Try another option.
Answer: Existing rows must receive a value or the column must be nullable
Existing records cannot satisfy a new NOT NULL column with no value. A temporary or permanent default, data backfill, or nullable design is required.
Question 57 of 60 · CRUD Operations using Entity Framework Core · Hard
Two requests load the same row with a rowversion concurrency token. Both modify it, and the first request saves successfully. What normally happens when the second request calls SaveChanges()?
Not quite. Try another option.
Answer: EF throws DbUpdateConcurrencyException
The generated update includes the original concurrency token in its predicate. After the first update changes the token, the second update affects zero rows and EF reports a concurrency conflict.
Question 58 of 60 · CRUD Operations using Entity Framework Core · Hard
A controller receives an entity graph from a client and calls Update(graph) directly. The graph omits a sensitive property that should remain unchanged. What is the major risk?
Not quite. Try another option.
Answer: EF may mark omitted or defaulted values as modified
Update commonly marks the entity graph as modified. Client-provided defaults or omitted values can overwrite stored data, so controlled model binding and explicit property updates are safer.
Question 59 of 60 · Authentication and Authorization in Web Applications · Hard
An ASP.NET Core application calls UseAuthorization() before UseAuthentication(). An endpoint requires an authenticated user. What is the likely consequence?
Not quite. Try another option.
Answer: Authorization may evaluate before the user is populated
Authentication middleware should run before authorization so HttpContext.User is established before authorization policies evaluate the request.
Question 60 of 60 · Authentication and Authorization in Web Applications · Hard
A policy requires claim scope=orders.read. A bearer token contains scope as the single string orders.read orders.write. A simple claim-value equality requirement is used. What is the likely result?
Not quite. Try another option.
Answer: The requirement fails because the value is one claim string
A basic claim requirement compares claim values and does not necessarily parse space-delimited scope strings. Scope-aware authorization must split or normalize the claim before comparison.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of CSE253 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of CSE253 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.