When you want to use a namespace across multiple Razor views without adding it to each view, where should you define it?

  • In the _ViewStart.cshtml file
  • In the _Layout.cshtml file
  • In the _ViewImports.cshtml file
  • In each individual Razor view
You should define a namespace that you want to use across multiple Razor views in the _ViewImports.cshtml file. This file is specifically designed to consolidate 'using' directives, making them accessible throughout the views that share it, thereby improving code organization and reusability.

In complex scenarios, instead of using simple roles or claims, you might need a custom authorization policy. How do you apply a custom policy using the [Authorize] attribute?

  • [Authorize(Policy = "CustomPolicy")]
  • [Authorize("CustomPolicy")]
  • [Authorize(CustomPolicy)]
  • [Authorize(Roles = "CustomPolicy")]
To apply a custom authorization policy using the [Authorize] attribute, you should use the syntax [Authorize(Policy = "CustomPolicy")]. This tells ASP.NET Core to use the "CustomPolicy" when authorizing access to the action or controller.

How can you conditionally branch the middleware pipeline based on specific criteria, like a request path or a header value?

  • Use conditional statements within middleware
  • Add custom middleware for branching
  • Utilize the UseWhen method
  • Modify the request object directly
To conditionally branch the middleware pipeline, you can use the UseWhen method provided by ASP.NET Core. This method allows you to specify a condition, and based on that condition, you can choose whether to execute certain middleware components or not. It's a powerful way to customize the pipeline based on specific criteria.

The Output property of a custom tag helper, of type _______, allows you to manipulate the final output of the tag helper.

  • string
  • int
  • TagHelperContent
  • object
The Output property of a custom tag helper is of type TagHelperContent. It allows you to manipulate the final HTML output produced by the tag helper, giving you fine-grained control over the generated markup. You can append, prepend, or replace content within the HTML element.

In which order does ASP.NET Core execute middleware components?

  • Sequentially in the order they are added
  • Random order
  • Alphabetical order
  • In parallel
ASP.NET Core executes middleware components sequentially in the order they are added to the application's request pipeline. This order is significant because it determines the sequence of processing for incoming requests and outgoing responses as they pass through each middleware component.

How can you define a route in ASP.NET Core to be available only for specific HTTP methods using attribute routing?

  • [HttpPut], [HttpPost]
  • [HttpGet], [HttpPost]
  • [HttpDelete], [HttpGet]
  • [HttpPatch], [HttpPut]
In ASP.NET Core, you can specify the HTTP methods a route should be available for using attributes like [HttpGet] or [HttpPost] above the controller action method. For example, [HttpGet] ensures the route is available for HTTP GET requests, and [HttpPost] for HTTP POST requests.

You're new to ASP.NET Core and are confused about where to specify the common design elements (like headers and footers) that appear on every page. Which Razor concept should you explore for this purpose?

  • ViewComponents
  • Razor Layouts
  • Partial Views
  • Tag Helpers
To specify common design elements like headers and footers that appear on every page, you should explore Razor Layouts. Razor Layouts allow you to define a shared layout for your views, enabling you to encapsulate these common elements.

When combining multiple [Authorize] attributes on a single action or controller, how does ASP.NET Core evaluate the requirements?

  • Logical AND
  • Logical OR
  • Randomly
  • Sequentially
ASP.NET Core evaluates the requirements of multiple [Authorize] attributes logically using AND. This means all authorization requirements specified in these attributes must be met for a user to access the action or controller.

SignalR is known for enabling ________ communication, which allows the server to push content to connected clients.

  • Real-time
  • Batch
  • Asynchronous
  • Synchronous
SignalR is a library in ASP.NET Core known for enabling real-time communication. It allows the server to push content to connected clients in real-time, making it ideal for applications that require instant updates, such as chat apps and live dashboards.

You've just started working on an ASP.NET Core project that uses Identity for user management. What are migrations primarily used for in this context?

  • Managing the database schema
  • Managing user authentication
  • Managing user roles
  • Managing user sessions
In an ASP.NET Core project with Identity, migrations are primarily used for managing the database schema. They allow you to create, update, and version your database schema as your application evolves. This is crucial for user management as it involves the creation and maintenance of user-related tables.

In an ASP.NET Core project, where are the application's dependencies and SDKs defined?

  • appsettings.json
  • Startup.cs
  • project.json
  • .csproj files
In an ASP.NET Core project, application dependencies and SDK versions are typically defined in the .csproj files. These files specify the packages, libraries, and tools required for the project. The .csproj files play a crucial role in managing the project's dependencies and ensuring the correct versions are used.

Which protocol does SignalR use primarily before falling back to other techniques?

  • WebSocket
  • HTTP
  • FTP
  • TCP
SignalR primarily uses the WebSocket protocol for real-time communication due to its low latency and bidirectional capabilities. WebSocket provides a full-duplex communication channel, making it ideal for applications requiring instant updates. SignalR gracefully falls back to other techniques like HTTP long polling or Server-Sent Events for compatibility with older browsers or network restrictions.