Unit 4: Backend Development Using ASP.NET Core - Practice Quiz

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

1 What is ASP.NET Core mainly used for?

Building Web Applications using ASP.NET Core Easy
A. Creating spreadsheet formulas
B. Managing computer hardware
C. Editing image files
D. Building web applications

2 In MVC architecture, which component handles user interface presentation?

MVC Architecture and Model-View-Controller Communication Easy
A. Controller
B. Model
C. View
D. Database

3 Which MVC component processes user requests?

MVC Architecture and Model-View-Controller Communication Easy
A. Controller
B. View
C. Model
D. Layout

4 What does an HTTP request usually represent?

Handling Requests and Responses Easy
A. A compiled program
B. A server configuration
C. A database table
D. A request from a client

5 What does an HTTP response contain?

Handling Requests and Responses Easy
A. A reply from the server
B. A programming language
C. A list of source files
D. A browser password

6 What is an action method in an ASP.NET Core controller?

Controllers and Actions Easy
A. A method that handles a request
B. A setting that starts the server
C. A class that creates tables
D. A file that stores styles

7 Which return type is commonly used by controller actions in ASP.NET Core MVC?

Controllers and Actions Easy
A. IRequestModel
B. IWebPage
C. IActionResult
D. IControllerFile

8 Which symbol starts a C# code expression in a Razor view?

Razor View Engine and Razor Syntax Easy
A. $
B. @
C. #
D. %

9 What is the main purpose of the Razor View Engine?

Razor View Engine and Razor Syntax Easy
A. To generate dynamic HTML
B. To configure network cables
C. To manage database backups
D. To compile device drivers

10 What is the purpose of a layout in ASP.NET Core MVC?

Layouts, Sections and View Start Easy
A. To define shared page structure
B. To store user passwords
C. To process database queries
D. To start background services

11 Which file commonly defines default view settings such as a layout?

Layouts, Sections and View Start Easy
A. _ViewStart.cshtml
B. Program.cs
C. appsettings.json
D. _Database.cshtml

12 Which data-passing technique uses dynamic properties?

Data Passing Techniques - ViewBag, ViewData and TempData Easy
A. ViewData
B. TempData
C. SessionState
D. ViewBag

13 Which technique is commonly used to pass data from one request to the next request?

Data Passing Techniques - ViewBag, ViewData and TempData Easy
A. ViewData
B. ViewBag
C. LocalData
D. TempData

14 What does a model usually represent in an MVC application?

Models Easy
A. The page color scheme
B. The browser address bar
C. Application data and rules
D. The server's power supply

15 What is session state used for?

Session and State Management Easy
A. Designing page icons
B. Storing user-specific data
C. Compiling Razor files
D. Creating HTML comments

16 Which HTML element is used to create a form?

ASP.NET Core Forms Easy
A. <section>
B. <header>
C. <form>
D. <table>

17 What does model binding do in ASP.NET Core MVC?

Model Binding Easy
A. Maps request data to model objects
B. Maps CSS rules to images
C. Maps routes to file folders
D. Maps views to database servers

18 What is the purpose of Tag Helpers in Razor views?

Tag Helpers Easy
A. To create operating system drivers
B. To encrypt all browser history
C. To replace the application database
D. To add server-side behavior to HTML elements

19 Where does server-side validation take place?

Server-Side Form Validations Easy
A. Inside the keyboard
B. Inside the monitor
C. On the web server
D. Only in the browser

20 Where does client-side validation usually take place?

Client-Side Form Validations Easy
A. On the web server only
B. In the database engine
C. In the user's browser
D. Inside the file system

21 You are creating an ASP.NET Core web application that must serve HTML pages, process form submissions, and access services through dependency injection. Which project type is the most appropriate starting point?

Building Web Applications using ASP.NET Core Medium
A. Windows Forms application with controllers
B. ASP.NET Core MVC web application
C. Class library with Razor files
D. Console application with HTTP listeners

22 In an MVC application, a controller receives a request, retrieves customer data, and returns a page displaying that data. Which sequence best represents the communication flow?

MVC Architecture and Model-View-Controller Communication Medium
A. View → Model → Controller → Browser
B. Model → Browser → View → Controller
C. Browser → Controller → Model → View
D. Controller → Browser → View → Model

23 An action must return a 404 Not Found response when a requested product does not exist. Which return statement is most suitable?

Handling Requests and Responses Medium
A. return NotFound();
B. return RedirectToAction("Index");
C. return BadRequest();
D. return View(product);

24 A controller contains the following action: public IActionResult Details(int id). A request is sent to /Products/Details/12. Assuming conventional routing, what value is assigned to id?

Controllers and Actions Medium
A. 12
B. The value of the controller name
C. The string "Details"
D. 0

25 Inside a Razor view, which syntax correctly displays the Name property of a model object?

Razor View Engine and Razor Syntax Medium
A. {{ Model.Name }}
B. @Model.Name
C. #Model.Name
D. <% Model.Name %>

26 A Razor view should display a paragraph only when Model.IsActive is true. Which code is correct?

Razor View Engine and Razor Syntax Medium
A. @when (Model.IsActive) { <p>Active</p> }
B. @condition (Model.IsActive): <p>Active</p>
C. @if (Model.IsActive) { <p>Active</p> }
D. @showif Model.IsActive { <p>Active</p> }

27 A layout contains @RenderSection("Scripts", required: false). What happens when a child view does not define a Scripts section?

Layouts, Sections and View Start Medium
A. The child view is rendered twice
B. The layout is skipped for that view
C. The section is ignored without an error
D. The application always throws an exception

28 A developer wants every Razor view in a folder and its subfolders to use the same layout without repeating Layout = ... in each view. Which file is intended for this configuration?

Layouts, Sections and View Start Medium
A. Program.cshtml
B. _ViewStart.cshtml
C. _ViewImports.cshtml
D. _LayoutConfig.cshtml

29 A controller redirects from one action to another and must display a one-time confirmation message after the redirect. Which data-passing mechanism is most appropriate?

Data Passing Techniques - ViewBag, ViewData and TempData Medium
A. ViewBag
B. TempData
C. A private controller field
D. ViewData

30 Which statement correctly describes the relationship between ViewBag and ViewData in ASP.NET Core MVC?

Data Passing Techniques - ViewBag, ViewData and TempData Medium
A. ViewData can only pass data to layouts
B. ViewBag persists data across redirects
C. They use completely separate storage systems
D. ViewBag is a dynamic wrapper around ViewData

31 A form collects fields from a database entity but should not allow users to submit properties such as IsAdmin or CreatedDate. Which modeling approach is safest?

Models Medium
A. Make restricted properties hidden inputs
B. Use a dedicated view model
C. Bind the complete entity directly
D. Store all fields in ViewBag

32 An ASP.NET Core application needs to store a small shopping-cart identifier for a user across multiple requests. Which configuration is required before using HttpContext.Session?

Session and State Management Medium
A. Place the value in the response body
B. Only enable endpoint routing
C. Add a second MVC controller
D. Register and configure a distributed cache

33 A form submits data to an action that creates a new record. Which pair of attributes is normally used to distinguish the display form action from the processing action?

ASP.NET Core Forms Medium
A. [HttpPost] for display and [HttpGet] for processing
B. [Route] for display and [Authorize] for processing
C. [HttpPut] for display and [HttpDelete] for processing
D. [HttpGet] for display and [HttpPost] for processing

34 An action has the signature public IActionResult Search(string category, int page = 1). A request is sent to /Products/Search?category=Books&page=3. What values are bound to the parameters?

Model Binding Medium
A. category is Books and page is 3
B. category is Search and page is Products
C. category is 3 and page is Books
D. category is null and page is 1

35 A form contains an input named Email, and the action parameter is string email. What allows ASP.NET Core model binding to associate the input with the parameter?

Model Binding Medium
A. The controller class name supplies the match
B. Matching names are used during binding
C. The browser automatically calls the model constructor
D. Only parameter order is considered

36 A Razor form uses <input asp-for="Email" />. What is a primary benefit of the asp-for Tag Helper?

Tag Helpers Medium
A. It generates markup connected to the model property
B. It creates a database table for Email
C. It redirects the request to an Email action
D. It disables server-side validation

37 A developer wants a link to call the Details action of the Products controller with id equal to 8. Which Tag Helper usage is correct?

Tag Helpers Medium
A. <a asp-link="Products/Details" asp-value="8">View</a>
B. <a asp-controller="Products" asp-action="Details" asp-route-id="8">View</a>
C. <a asp-route-controller="Products" asp-route-action="Details" id="8">View</a>
D. <a controller="Products" action="Details" route="8">View</a>

38 After submitting a model with a required property left empty, which check should a controller perform before saving the data?

Server-Side Form Validations Medium
A. Response.HasStarted
B. User.Identity.IsAuthenticated only
C. Request.HasFormContentType only
D. ModelState.IsValid

39 A model property has the attribute [StringLength(20, MinimumLength = 5)]. Which input satisfies this validation rule?

Server-Side Form Validations Medium
A. A four-character value
B. A twenty-one-character value
C. A five-character value
D. An empty value without other attributes

40 A form uses validation attributes and Tag Helpers, but validation messages do not appear until the form is submitted to the server. Which missing component is the most likely cause?

Client-Side Form Validations Medium
A. The controller constructor
B. The jQuery Validation scripts
C. The database connection string
D. The session middleware

41 An ASP.NET Core application must serve MVC pages, JSON APIs, and static files. Which middleware and endpoint configuration best preserves conventional MVC routing while allowing all three workloads?

Building Web Applications using ASP.NET Core Hard
A. Use only MapControllers because MVC views and static files are discovered automatically.
B. Use UseStaticFiles, UseRouting, UseAuthorization, and MapControllerRoute with a conventional pattern.
C. Use UseRouting, UseEndpoints, and register static files inside the MVC controller pipeline.
D. Use UseMvc after UseAuthorization and omit endpoint mapping in the application.

42 A controller receives an entity from a repository, but the view must display calculated totals and omit internal fields. Which design most appropriately preserves MVC responsibilities?

MVC Architecture and Model-View-Controller Communication Hard
A. Store the entity in TempData and reconstruct the display model in the view.
B. Project the entity into a dedicated view model in the controller or application layer.
C. Pass the entity directly and calculate totals inside the Razor view.
D. Add presentation-only properties to the database entity and bind the view to it.

43 A POST action successfully creates a resource and must prevent duplicate submission when the user refreshes the browser. Which response pattern is most appropriate?

Handling Requests and Responses Hard
A. Return NotFound so the browser cannot repeat the request.
B. Return the same view with status code 200 OK.
C. Return RedirectToAction to the resource or confirmation page.
D. Return View with the submitted model and status code 201 Created.

44 An action returns BadRequest() for malformed input, Unauthorized() for an unauthenticated request, and Forbid() for an authenticated user lacking permission. Which interpretation is correct?

Handling Requests and Responses Hard
A. Forbid redirects every user to the login page.
B. BadRequest indicates invalid request syntax or input.
C. Unauthorized means authenticated but missing a required role.
D. Forbid means the request body could not be parsed.

45 Two actions in the same controller are named Search, one accepting string term and one accepting int id. Requests to /Products/Search?value=12 produce an ambiguous action error. Why?

Controllers and Actions Hard
A. Action selection does not use arbitrary parameter types as a reliable overload discriminator.
B. Query-string values are always converted to strings before action selection.
C. The controller cannot contain two actions with the same method name.
D. The Search route is reserved for API controllers only.

46 A controller action accepts a complex parameter named order, and the request contains order.Customer.Name=Lee. What does successful model binding generally require?

Controllers and Actions Hard
A. The model must inherit from ControllerBase.
B. The action parameter must be decorated with [FromRoute].
C. The request must contain JSON because complex types ignore form keys.
D. The binder must find a compatible value provider and writable nested properties.

47 In a Razor view, @Model.Name is rendered as HTML-encoded text, while @Html.Raw(Model.Name) renders markup contained in the value. Which security conclusion is correct?

Razor View Engine and Razor Syntax Hard
A. Html.Raw prevents XSS by converting markup into text before rendering.
B. Both expressions encode markup because Razor always sanitizes strings.
C. Html.Raw should be used only when the content is trusted or safely sanitized.
D. Model.Name is unsafe because Razor encoding is disabled for model properties.

48 A Razor loop contains @if (item.IsActive) { <span>Active</span> }. The markup is emitted only for active items. Which Razor behavior explains this?

Razor View Engine and Razor Syntax Hard
A. Razor switches between code and markup contexts based on syntax boundaries.
B. Razor treats all markup inside code blocks as literal C# strings.
C. The view engine replaces conditional markup with a client-side script.
D. The compiler executes HTML before evaluating the if expression.

49 A shared _ViewStart.cshtml sets Layout = "_MainLayout", but one view must use a different layout. What is the correct approach?

Layouts, Sections and View Start Hard
A. Define a second @section Layout inside the view.
B. Change _ViewImports.cshtml because it overrides layout inheritance.
C. Use ViewData to replace the layout after the view begins rendering.
D. Set the alternative Layout value in the view itself.

50 A layout declares @RenderSection("Scripts", required: true). A view does not define that section, and no fallback is provided. What is the result?

Layouts, Sections and View Start Hard
A. The layout silently renders an empty section.
B. The section is automatically populated from _ViewImports.cshtml.
C. Rendering fails because the required section is missing.
D. The view renders, but scripts move to the document head.

51 A controller assigns ViewData["Notice"] = "Saved" and returns a view. The view reads ViewBag.Notice. What is expected?

Data Passing Techniques - ViewBag, ViewData and TempData Hard
A. The value is available because ViewBag and ViewData share the same underlying dictionary.
B. The value is unavailable because ViewBag works only with controller properties.
C. The value is converted to JSON before ViewBag can read it.
D. The value survives a redirect because all view data is session-backed.

52 A POST action sets TempData["Message"] and redirects to a GET action. The GET reads the message once and renders a view. What is the typical behavior?

Data Passing Techniques - ViewBag, ViewData and TempData Hard
A. The message remains permanently until the application restarts.
B. The message is unavailable because redirects clear controller state.
C. The message is available only if it is also copied into ViewBag.
D. The message is available during the next request and usually removed after it is read.

53 A domain model has a calculated Total property with only a getter, while a posted form contains a Total field supplied by the client. What is the safest design?

Models Hard
A. Make Total writable so the default binder can populate it.
B. Bind directly to the domain model and trust the posted total.
C. Recalculate Total on the server from trusted posted inputs.
D. Store the posted total in ViewBag and use it during persistence.

54 An application uses session state in a multi-instance deployment. Users intermittently lose session values after requests are routed to different instances. Which solution addresses the underlying problem?

Session and State Management Hard
A. Store session values in ViewData so they become instance independent.
B. Increase the controller action timeout to preserve session affinity.
C. Enable session middleware without changing the deployment.
D. Use a distributed session store shared by all application instances.

55 A developer stores a large object graph in ASP.NET Core session and observes serialization overhead and stale values across requests. Which change is most appropriate?

Session and State Management Hard
A. Copy the entire object graph into TempData on every request.
B. Store only small identifiers or essential state and reload current data.
C. Disable cookies so session values are reconstructed automatically.
D. Use session as the primary database for the object graph.

56 A Razor form submits a POST request to an action protected by antiforgery validation. The form was generated with the Form Tag Helper. What must normally be present for validation to succeed?

ASP.NET Core Forms Hard
A. Only a query-string token appended to the form action.
B. A manually added Authorization header containing the user password.
C. A session value named __RequestVerificationToken only.
D. The antiforgery token generated by the form plus the associated request cookie.

57 An action has [HttpPost] public IActionResult Save([Bind("Name,Price")] Product product). The posted form also includes IsAdmin=true. What happens to IsAdmin during binding?

Model Binding Hard
A. It is bound only when the request is sent as JSON.
B. It is ignored because it is excluded by the bind include list.
C. It is bound and then overwritten by the database automatically.
D. It causes model binding to fail for the entire product.

58 A form posts Items[0].Name, Items[2].Name, and Items[3].Name, omitting index 1. Under indexed collection binding conventions, what issue can occur?

Model Binding Hard
A. The binder converts all item names into a single comma-separated string.
B. The request is rejected before model validation runs.
C. The binder always creates four objects and leaves index 1 empty.
D. Binding may stop at the gap, so later items may not bind as expected.

59 A form uses <input asp-for="Email" /> and the model state contains an invalid submitted value. The model property has a different value set by the controller before returning the view. Which value is typically rendered?

Tag Helpers Hard
A. The Tag Helper reads only the database value and ignores both sources.
B. The value from model state typically takes precedence over the model property.
C. The input is left empty whenever model validation fails.
D. The controller's model property always takes precedence.

60 A POST action checks ModelState.IsValid, but a malicious client submits an invalid date string. Why must the action still perform this check before using the model?

Server-Side Form Validations Hard
A. The browser guarantees valid values for every submitted form field.
B. Data annotations execute only after the action returns a view.
C. Binding conversion errors are recorded in ModelState even when attributes are absent.
D. Invalid values are silently converted to secure defaults by the framework.