Unit 5: ASP.NET Core MVC, Entity Framework Core and Security - Practice Quiz

CSE253 — .Net Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of the middleware request pipeline in ASP.NET Core?

Middleware Request Pipeline Easy
A. To compile Razor views only
B. To process HTTP requests and responses
C. To store user passwords
D. To create database tables

2 In an ASP.NET Core application, middleware components are generally executed in what order?

Middleware Request Pipeline Easy
A. Random order for each request
B. Alphabetical order by class name
C. Reverse database table order
D. The order in which they are registered

3 Which middleware is commonly used to serve static files in ASP.NET Core?

Built-In Middleware and Custom Middleware Easy
A. Entity Framework Middleware
B. Model Binding Middleware
C. Database Migration Middleware
D. Static File Middleware

4 What is custom middleware?

Built-In Middleware and Custom Middleware Easy
A. Middleware written for a specific application need
B. A compiler setting for controllers
C. A database table generated by a model
D. A built-in HTML validation rule

5 What is the main purpose of dependency injection in ASP.NET Core?

Dependency Injection in ASP.NET Core Easy
A. To provide required objects to classes
B. To encrypt every database column
C. To create browser cookies automatically
D. To convert HTML into SQL

6 Where are application services commonly registered for dependency injection?

Dependency Injection in ASP.NET Core Easy
A. In the application service container
B. In the CSS stylesheet
C. In the browser history
D. In the database connection string

7 What is Entity Framework Core primarily used for?

Introduction to Entity Framework Core Easy
A. Creating image files
B. Designing web page colors
C. Working with databases through .NET objects
D. Managing operating system users

8 What does ORM stand for?

Introduction to Entity Framework Core Easy
A. Object Routing Module
B. Open Resource Model
C. Online Request Manager
D. Object-Relational Mapper

9 What is the role of the DbContext class in Entity Framework Core?

DbContext and Entity Configuration Easy
A. It manages database interaction and entity tracking
B. It defines the application's visual theme
C. It handles only browser navigation
D. It replaces all controller classes

10 Which property type in a DbContext usually represents a database table?

DbContext and Entity Configuration Easy
A. ViewDataDictionary
B. HttpRequest
C. IActionResult
D. DbSet<TEntity>

11 What is created first in the Entity Framework Core Code First approach?

Code First Approach Easy
A. The production database backup
B. The SQL server log file
C. The application classes and model
D. The browser user interface

12 Which feature is commonly used to apply Code First model changes to a database?

Code First Approach Easy
A. CSS selectors
B. HTTP headers
C. Razor comments
D. Entity Framework migrations

13 What is the starting point in the Database First approach?

Database First Approach Easy
A. An empty controller
B. A browser session
C. A CSS framework
D. An existing database

14 What is commonly generated from an existing database in the Database First approach?

Database First Approach Easy
A. Only authentication cookies
B. Only HTML images
C. Entity classes and a DbContext
D. Only CSS variables

15 What is the purpose of a database migration in Entity Framework Core?

Database Migrations Easy
A. To record and apply model structure changes
B. To format controller source code
C. To authenticate database users
D. To compress web page images

16 Which command is commonly used to create a new Entity Framework Core migration?

Database Migrations Easy
A. dotnet web database open
B. dotnet mvc controller start
C. dotnet ef migrations add
D. dotnet core schema view

17 What does the letter C represent in CRUD?

CRUD Operations using Entity Framework Core Easy
A. Connect
B. Compile
C. Create
D. Configure

18 Which method marks a new entity for insertion into the database?

CRUD Operations using Entity Framework Core Easy
A. Add
B. Remove
C. Update
D. Find

19 What does authentication verify?

Authentication and Authorization in Web Applications Easy
A. The size of a database
B. The style of a web page
C. The identity of a user
D. The order of middleware

20 What does authorization determine?

Authentication and Authorization in Web Applications Easy
A. Which CSS file loads first
B. Whether a password is typed quickly
C. What an authenticated user may access
D. How a database is backed up

21 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)?

Middleware Request Pipeline Medium
A. After writing both request and response logs
B. Only when the response status indicates failure
C. Before writing both request and response logs
D. Between the request log and the response log

22 A middleware component returns a response without invoking the next middleware. What is the effect on the request pipeline?

Middleware Request Pipeline Medium
A. The remaining middleware components are skipped
B. The request is automatically sent to an MVC controller
C. The remaining middleware run in reverse order
D. The pipeline restarts from the first middleware

23 An application should serve files from wwwroot without routing those requests through MVC controllers. Which built-in middleware should be added?

Built-In Middleware and Custom Middleware Medium
A. app.UseRouting()
B. app.UseAuthorization()
C. app.UseStaticFiles()
D. app.UseExceptionHandler()

24 A conventional custom middleware class receives a RequestDelegate through its constructor. Which method signature allows ASP.NET Core to execute it?

Built-In Middleware and Custom Middleware Medium
A. Task InvokeAsync(HttpContext context)
B. IResult HandleAsync(HttpResponse response)
C. void Configure(HttpContext context)
D. Task ExecuteAsync(HttpRequest request)

25 A service stores information that must be shared within one HTTP request but isolated from other requests. Which lifetime should be used?

Dependency Injection in ASP.NET Core Medium
A. Scoped
B. Singleton
C. Static
D. Transient

26 A controller constructor requires IEmailSender, but no implementation has been registered. What normally happens when ASP.NET Core tries to create the controller?

Dependency Injection in ASP.NET Core Medium
A. The controller is created without its constructor
B. The parameter receives a null value
C. Service resolution throws an exception
D. A default implementation is generated

27 A queried entity is modified in memory and SaveChangesAsync() is called without explicitly calling Update. Why can Entity Framework Core persist the modification?

Introduction to Entity Framework Core Medium
A. The change tracker detects modified property values
B. The LINQ query immediately updates the database
C. The entity class executes an implicit SQL command
D. The database compares every table row automatically

28 The same EF Core model must run against SQL Server in production and SQLite during local testing. Which EF Core feature primarily enables this?

Introduction to Entity Framework Core Medium
A. Middleware environment branches
B. Razor view compilation
C. Replaceable database providers
D. Automatic controller discovery

29 A Blog has many Post entities, and every Post has one required Blog. Which Fluent API configuration best represents this relationship?

DbContext and Entity Configuration Medium
A. HasMany(b => b.Posts).WithMany(p => p.Blog).IsRequired()
B. HasMany(b => b.Posts).WithOne(p => p.Blog).IsRequired()
C. HasOne(b => b.Posts).WithMany(p => p.Blog).IsRequired()
D. HasOne(b => b.Posts).WithOne(p => p.Blog).IsRequired()

30 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?

DbContext and Entity Configuration Medium
A. In OnModelCreating using the Fluent API
B. In SaveChanges using change tracking
C. In Program.cs using endpoint routing
D. In the controller using model binding

31 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?

Code First Approach Medium
A. Delete the DbContext and rebuild the project
B. Rescaffold all entities from the database
C. Modify only the MVC controller and restart
D. Create a migration and update the database

32 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?

Code First Approach Medium
A. As an ignored property by convention
B. As a computed column by convention
C. As the primary key by convention
D. As an optional foreign key by convention

33 A team has an existing SQL Server database and needs to generate EF Core entity classes and a DbContext. Which command is appropriate?

Database First Approach Medium
A. dotnet ef migrations script
B. dotnet ef database update
C. dotnet ef migrations add
D. dotnet ef dbcontext scaffold

34 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?

Database First Approach Medium
A. Store the behavior in the database connection string
B. Move the behavior into the migration snapshot
C. Add the behavior directly to the generated file
D. Add the behavior in a separate partial class

35 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?

Database Migrations Medium
A. dotnet ef migrations remove
B. dotnet ef dbcontext optimize
C. dotnet ef migrations list
D. dotnet ef database drop

36 A production administrator needs a reviewable SQL script containing database changes between two migrations. Which command should the developer use?

Database Migrations Medium
A. dotnet ef migrations script
B. dotnet ef database update
C. dotnet ef migrations add
D. dotnet ef dbcontext scaffold

37 A read-only product listing loads thousands of rows and does not modify them. Which query is generally more efficient?

CRUD Operations using Entity Framework Core Medium
A. context.Products.UpdateRange().ToListAsync()
B. context.Products.RemoveRange().ToListAsync()
C. context.Products.AddRange().ToListAsync()
D. context.Products.AsNoTracking().ToListAsync()

38 A controller must delete an order only when it exists. Which sequence correctly performs the operation?

CRUD Operations using Entity Framework Core Medium
A. Create a migration, remove the entity, then scaffold the context
B. Find the order, call Add, then call SaveChangesAsync
C. Find the order, call Remove, then call SaveChangesAsync
D. Query the order with AsNoTracking, then call AddRange

39 An ASP.NET Core application uses cookie authentication and protected endpoints. Which middleware order is required after routing and before endpoint execution?

Authentication and Authorization in Web Applications Medium
A. UseStaticFiles() followed by UseAuthentication()
B. UseAuthorization() followed by UseAuthentication()
C. UseExceptionHandler() followed by UseAuthorization()
D. UseAuthentication() followed by UseAuthorization()

40 An action should be accessible only to authenticated users who satisfy a policy named CanApproveOrders. Which attribute is appropriate?

Authentication and Authorization in Web Applications Medium
A. [Authorize(Policy = "CanApproveOrders")]
B. [ValidateAntiForgeryToken(Policy = "CanApproveOrders")]
C. [Authorize(Role = "CanApproveOrders")]
D. [AllowAnonymous(Policy = "CanApproveOrders")]

41 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?

Middleware Request Pipeline Hard
A. UseRouting
B. UseStaticFiles
C. UseExceptionHandler
D. UseAuthorization

42 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?

Middleware Request Pipeline Hard
A. The current middleware is skipped automatically
B. The after-code executes before the short-circuiting middleware
C. The current before-code and after-code both execute
D. Only the current middleware's before-code executes

43 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?

Built-In Middleware and Custom Middleware Hard
A. Before UseStaticFiles and before UseRouting
B. Inside UseExceptionHandler after the exception branch
C. After UseStaticFiles and before endpoint execution
D. After MapControllers and before Run

44 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?

Built-In Middleware and Custom Middleware Hard
A. The identifier cannot be added to response headers
B. The field may be overwritten by another request
C. The middleware cannot access HttpContext
D. The middleware is forced into scoped lifetime

45 A singleton service directly depends on a scoped DbContext. What is the correct assessment of this dependency graph?

Dependency Injection in ASP.NET Core Hard
A. It is valid only when the context uses no tracking
B. It is invalid because a singleton captures a shorter-lived dependency
C. It is invalid only when the application uses multiple databases
D. It is valid because the singleton resolves the context per method call

46 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?

Dependency Injection in ASP.NET Core Hard
A. A single composite handler created automatically
B. All registered descriptors in registration order
C. Only the last registered handler
D. Only the first registered handler

47 An EF Core query projects entities into DTOs and uses AsNoTracking(). Later, the application modifies one projected DTO and calls SaveChanges(). What happens?

Introduction to Entity Framework Core Hard
A. An update occurs because projections are always tracked
B. EF updates only scalar properties matching DTO names
C. EF automatically tracks and updates the source entity
D. No update occurs unless an entity is explicitly attached

48 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?

Introduction to Entity Framework Core Hard
A. The method runs automatically on the database server
B. EF silently replaces the method with a constant
C. The entire table is always loaded before filtering
D. EF throws an exception for unsupported client evaluation

49 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?

DbContext and Entity Configuration Hard
A. The model snapshot against the current model
B. The database data against entity instances
C. Only the current database schema
D. The provider's default conventions against SQL metadata

50 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?

DbContext and Entity Configuration Hard
A. Lazy loading does not occur for the non-virtual navigation
B. Lazy loading works because foreign keys imply proxies
C. Lazy loading works only for required relationships
D. The relationship becomes optional at runtime

51 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?

Code First Approach Hard
A. During migration creation only
B. When the migration is applied to the database
C. During model class compilation
D. Only when an invalid row is queried later

52 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?

Code First Approach Hard
A. The database server's current UTC timestamp
B. A NULL value despite the non-nullable property
C. A value generated from the migration timestamp
D. The CLR default value for DateTime

53 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?

Database First Approach Hard
A. The connection string is encrypted permanently
B. The custom edits may be overwritten
C. The database schema is reverted automatically
D. The generated context stops tracking entities

54 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?

Database First Approach Hard
A. Scaffolding automatically adds a required validation rule
B. The provider converts every NULL to zero
C. EF changes the database column to NOT NULL
D. The compiler or runtime exposes a nullability mismatch

55 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?

Database Migrations Hard
A. The migration runs only in development environments
B. Each instance always creates a different schema
C. Concurrent migration execution can cause locking or race failures
D. The migration history table is ignored by both instances

56 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?

Database Migrations Hard
A. Existing rows must receive a value or the column must be nullable
B. The migration must disable foreign-key constraints permanently
C. The column must be converted to a primary key
D. The table must be recreated without indexes

57 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()?

CRUD Operations using Entity Framework Core Hard
A. EF throws DbUpdateConcurrencyException
B. EF merges both property sets automatically
C. The second update overwrites the first unconditionally
D. The second update is ignored without an exception

58 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?

CRUD Operations using Entity Framework Core Hard
A. EF may mark omitted or defaulted values as modified
B. EF always converts the graph into an insert
C. EF disables concurrency checks for the graph
D. EF refuses to track graphs from HTTP requests

59 An ASP.NET Core application calls UseAuthorization() before UseAuthentication(). An endpoint requires an authenticated user. What is the likely consequence?

Authentication and Authorization in Web Applications Hard
A. Authorization may evaluate before the user is populated
B. Authentication runs automatically after endpoint execution
C. Authorization always authenticates using every configured scheme
D. The endpoint becomes anonymous because authorization is disabled

60 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?

Authentication and Authorization in Web Applications Hard
A. The requirement fails because scope claims cannot be authorized
B. The requirement succeeds only for cookie authentication
C. The requirement succeeds because token scopes are always split
D. The requirement fails because the value is one claim string