Which attribute would be used to enforce that a specific route parameter should be of type integer?
- [Route]
- [HttpGet]
- [FromRoute]
- [RegularExpression]
The [FromRoute] attribute is used to bind a route parameter to an action method parameter in ASP.NET Core. If you want to enforce that the parameter should be of a specific type, like integer, you can add the appropriate data type constraint in your action method's parameter using C# data type annotations.
To define relationships, constraints, or to configure non-entity types, you should override the _________ method in the DbContext.
- OnModelCreating
- OnEntityConfiguration
- ConfigureModel
- EntityOverrides
In ASP.NET Core Entity Framework, you should override the OnModelCreating method in the DbContext class. This method allows you to configure the database model, define relationships, and apply various constraints using Fluent API or data annotations.
When using the [Authorize] attribute with policies, the specified policy name must be previously registered in the _________.
- Startup.cs
- Program.cs
- appsettings.json
- ConfigureServices method
When using the [Authorize] attribute with policies, the specified policy name must be previously registered in the ConfigureServices method within the Startup.cs file. This is where you define and configure your authorization policies, associating them with specific requirements and roles.
If you want to set up a project with user authentication mechanisms built-in, which template should you opt for?
- Empty
- Web Application
- Web API
- Individual User Accounts
The "Individual User Accounts" template is the one to choose when you want to set up a project with built-in user authentication mechanisms. This template includes user registration, login, and management features out of the box, making it easier to create applications that require user authentication.
While testing the registration page, you notice that users can register with very weak passwords. How can you enforce stricter password policies in ASP.NET Core?
- Use Data Annotations
- Implement Custom Validation
- Configure Identity Options
- Update Entity Framework Core
To enforce stricter password policies in ASP.NET Core, you can configure Identity Options. ASP.NET Core Identity provides built-in password policies that you can customize to require stronger passwords. You can define password complexity rules, including minimum length, required characters, and more in the Identity Options configuration.
Which Razor helper is primarily used to generate form elements in an ASP.NET Core view?
- @Html.Form
- @Html.TextBox
- @Html.ActionLink
- @Html.BeginForm
The correct option is @Html.BeginForm. This Razor helper is used to generate the opening
How can you protect a controller action to be accessible only by users with the role "Admin" using the [Authorize] attribute?
- [Authorize(Roles = "Admin")]
- [Authorize("Admin")]
- [Authorize(Admin)]
- [Authorize(Role = "Admin")]
To restrict a controller action to users with the "Admin" role, you should use the [Authorize(Roles = "Admin")] attribute. This attribute ensures that only users with the specified role can access the action.
You are creating a website and want to add a folder for storing images, scripts, and CSS files. Which default folder in ASP.NET Core would you typically use?
- wwwroot
- App_Data
- Views
- Controllers
In ASP.NET Core, the 'wwwroot' folder is the default location for storing static web assets like images, scripts, and CSS files. These assets can be directly served to clients without the need for additional routing.
What distinguishes the Kestrel web server in the ASP.NET Core ecosystem?
- It's a Windows-exclusive web server
- It's a cross-platform, lightweight, and high-performance web server
- It's a reverse proxy server
- It's used for database management
Kestrel is a distinctive component in the ASP.NET Core ecosystem because it's a cross-platform, lightweight, and high-performance web server. Unlike some other web servers that are platform-specific, Kestrel can run on Windows, Linux, and macOS, making it a preferred choice for ASP.NET Core hosting. It is often used in combination with reverse proxy servers like Nginx or IIS for production scenarios.
Which file in an ASP.NET Core project typically contains project metadata, package dependencies, and project-specific settings?
- Program.cs
- Startup.cs
- appsettings.json
- project.json
The appsettings.json file in an ASP.NET Core project typically contains project metadata, package dependencies, and project-specific settings. It's a JSON configuration file used to store various configuration values for the application, such as database connection strings, logging settings, and custom application settings. This separation of configuration from code promotes flexibility and maintainability in ASP.NET Core applications.
If you want to specify multiple roles for an action or a controller using the [Authorize] attribute, how would you do it?
- [Authorize(Roles = "Admin, Manager")]
- [Authorize(Role = "Admin", Role = "Manager")]
- [Authorize("Admin, Manager")]
- [Authorize("Admin", "Manager")]
To specify multiple roles using the [Authorize] attribute, you can separate them with commas inside the Roles parameter, like this: [Authorize(Roles = "Admin, Manager")]. This allows access to the action or controller for users who belong to either the "Admin" role or the "Manager" role or both.
In ASP.NET Core, custom middlewares can be created using a delegate with the signature _______.
- Func
- Action
- Func
- MiddlewareDelegate
Custom middlewares in ASP.NET Core are created using a delegate with the signature Func. This delegate takes an HttpContext as input and returns a Task, allowing you to write custom logic to handle requests and responses in the pipeline.