If you wish to control the scope of your Tag Helpers (i.e., which views or pages they are available in), which file should you modify?

  • Startup.cs
  • appsettings.json
  • _ViewImports.cshtml
  • Program.cs
To control the scope of your Tag Helpers, you should modify the _ViewImports.cshtml file. This file is where you can import namespaces and specify which Tag Helpers should be available globally across your views or pages.

You're developing a web application where you want to set up pages for different categories. The URL should look like /categoryName. How would you define the routing for this requirement?

  • Use attribute routing
  • Configure a conventional route
  • Use a query string
  • Define a wildcard route
To achieve URLs like /categoryName in ASP.NET Core, you can configure a conventional route. This involves setting up a route template in your application's startup, which specifies the desired URL structure and how it maps to controller actions.

What is the primary purpose of the Startup.cs file in an ASP.NET Core application?

  • Managing database connections
  • Defining routes and handling HTTP requests
  • Storing application settings
  • Handling user authentication
The primary purpose of the Startup.cs file is to configure the application's request handling pipeline. It defines how HTTP requests are processed, which controllers and actions handle them, and how various middleware components are configured. Additionally, it sets up services, defines routes, and performs other initialization tasks necessary for the application to run.

For more advanced configurations, developers can make use of the _________ method inside the DbContext to execute any arbitrary SQL commands.

  • Sql
  • ExecuteSql
  • Query
  • ExecuteSqlCommand
In Entity Framework Core, developers can use the ExecuteSqlCommand method inside the DbContext to execute arbitrary SQL commands. This is especially useful for advanced configurations, data migrations, or when you need to perform database operations that are not supported by LINQ.

You've been tasked with updating the user table to include a new field for "MiddleName." After adding this field to the appropriate model class, what would be the next step to ensure the database is updated?

  • Run dotnet ef migrations add
  • Manually update the database schema
  • No further steps are required
  • Run dotnet build
After adding the new field to the model class, you should run the dotnet ef migrations add command to generate a new migration. This migration will contain the necessary changes to update the database schema. Manually updating the schema is not recommended as it can lead to inconsistencies.

For securing APIs in ASP.NET Core, which authentication method is recommended?

  • Basic Authentication
  • Windows Authentication
  • Token-based Authentication
  • Digest Authentication
For securing APIs in ASP.NET Core, token-based authentication is recommended. Token-based authentication, often using technologies like OAuth 2.0 or JWT (JSON Web Tokens), provides a secure and scalable way to authenticate and authorize users for API access. It's widely adopted for modern API security scenarios.

In ASP.NET Core Identity, how can you enforce that passwords must contain a special character during user registration?

  • Using a Regular Expression
  • Configuration File
  • Custom Middleware
  • Dependency Injection
In ASP.NET Core Identity, you can enforce password complexity rules, such as requiring special characters, by using a regular expression pattern. This pattern is typically configured in the Startup.cs or a similar configuration file and defines the password policy.

You've modified the properties of the IdentityUser class in your ASP.NET Core project. Before deploying these changes to production, which of the following steps is crucial to ensure the database reflects these modifications?

  • Delete the existing database and recreate it
  • Run Entity Framework Core's "Add-Migration" command
  • Manually update the database schema
  • No action needed
To ensure the database reflects the modified IdentityUser class, you should run Entity Framework Core's "Add-Migration" command. This command generates a new migration containing the necessary SQL scripts to update the database schema to match the changes made to your model.

In ASP.NET Core, how can you enforce an authenticated user to have a specific role to access a resource?

  • Use the [Authorize] attribute with the "Roles" parameter
  • Use the [AllowAnonymous] attribute
  • Use the [Authorize] attribute with the "Permissions" parameter
  • Use the [Authorize] attribute without any parameters
To enforce that only users with a specific role can access a resource, you should use the [Authorize] attribute with the "Roles" parameter. This restricts access to users who belong to the specified role.

Which directive in _ViewImports.cshtml allows you to set the base class for the Razor views?

  • @inherits
  • @model
  • @using
  • @layout
The correct directive to set the base class for Razor views in _ViewImports.cshtml is @inherits. This directive specifies the full name of the class that the view should inherit from. It allows you to establish a custom base class for all views in a folder or the entire application, enabling you to add shared functionality to your views.