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 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.

Your application requires some complex queries which might not be easily achievable using LINQ. With Entity Framework Core, how can you directly execute SQL queries against the database?

  • FromSqlRaw
  • ExecuteSqlCommand
  • RunSqlQuery
  • QuerySQL
In Entity Framework Core, you can directly execute raw SQL queries against the database using the FromSqlRaw method. This allows you to write custom SQL queries when LINQ isn't suitable for your complex query requirements, but it should be used with caution to prevent SQL injection vulnerabilities.

In a new project, you are given the responsibility to handle user registration. Your senior developer mentions that there's a built-in way in ASP.NET Core to manage users. What is this system called?

  • Identity
  • Middleware
  • Entity Framework
  • Dependency Injection
The built-in system in ASP.NET Core to manage users is called ASP.NET Core Identity. It's a framework for handling user authentication, authorization, and account management tasks, making it easier to implement user registration and management in your application.

How does the Razor view engine resolve the directives when multiple _ViewImports.cshtml files exist in different directories of the project?

  • Directives in the nearest _ViewImports.cshtml override directives in parent directories
  • Directives in parent directories override directives in the nearest _ViewImports.cshtml
  • Directives in the nearest _ViewImports.cshtml are combined with directives in parent directories
  • Directives in _ViewImports.cshtml are ignored in this scenario
The Razor view engine resolves directives by giving precedence to the nearest _ViewImports.cshtml file in the directory hierarchy. Directives in the nearest file will override those in parent directories, allowing for granular control over view behavior.

The __________ folder in an ASP.NET Core project generally contains view templates.

  • Views
  • Models
  • Controllers
  • Migrations
The "Views" folder in an ASP.NET Core project typically contains view templates. These templates are used to define the user interface of the application, including the HTML markup and rendering logic for web pages. Views play a crucial role in separating the presentation layer from the application's logic.

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.