Using the {id:int} syntax in an attribute route enforces that the id parameter must be of type ______.
- String
- Integer
- Double
- DateTime
The {id:int} syntax in an attribute route specifies that the id parameter must be of type integer. This is a way to ensure that the data passed in the URL is an integer value, and if it's not, the route won't match.
For projects focused on background tasks and might run as Windows services or Linux daemons, you should use the ________ template.
- Worker
- Web API
- Blazor
- MVC
The Worker template in ASP.NET Core is specifically designed for projects that focus on background tasks. It's ideal for creating services that perform work in the background and can be run as Windows services or Linux daemons. This template provides the necessary infrastructure for background task execution.
What's the main difference between using Database.EnsureCreated() and Migrations in Entity Framework Core?
- Database.EnsureCreated() creates a database if it doesn't exist, ignoring migrations
- Migrations allow for version control and tracking of database schema changes
- Database.EnsureCreated() is used for unit testing only
- Migrations are slower than EnsureCreated()
The main difference is that Database.EnsureCreated() creates a database without tracking schema changes, often used for development or unit testing, whereas migrations provide version control for your database schema, allowing you to apply, rollback, and manage changes over time.
Continuous _________ is a software development practice where changes in the code are automatically tested and prepared for a release to production.
- Integration
- Deployment
- Testing
- Delivery
Continuous Delivery is a software development practice where changes are automatically tested and prepared for release to production. It includes automated testing, deployment, and delivery of code changes.
For a Web API, you're required to ensure that only authenticated users can access specific endpoints, but some endpoints should be public. How would you achieve this in ASP.NET Core?
- Use Authentication Filters
- Use Authorization Filters
- Configure Middleware
- Use Role-Based Authorization
To control access to specific endpoints in an ASP.NET Core Web API, you'd use Authorization Filters. You can apply policies to controllers or actions, and these filters can determine whether a user is authorized to access the resource based on their identity and role. To make some endpoints public, you can use AllowAnonymous attribute or configure policies accordingly.
Which template should you choose when you need both Razor-based web pages and API controllers?
- Web Application
- Web API
- Empty
- Blazor
The "Web Application" template is the suitable choice when you need both Razor-based web pages for user interfaces and API controllers for handling data interactions. This template provides a balanced setup for creating web applications that combine server-rendered Razor pages with APIs for data exchange.
What is the primary difference between the _ViewImports.cshtml and _ViewStart.cshtml files in Razor?
- _ViewImports.cshtml sets directives and namespaces
- _ViewStart.cshtml sets layout and common code
- They serve the same purpose
- _ViewStart.cshtml sets routing rules
The primary difference between _ViewImports.cshtml and _ViewStart.cshtml in Razor is their purpose. _ViewImports.cshtml is used to set directives, namespaces, and base class declarations for views, whereas _ViewStart.cshtml is used to specify common layout code and execute code before rendering views. _ViewStart.cshtml is typically used to set layout and execute code that should apply globally to multiple views.
When securing your ASP.NET Core Web APIs, which authentication approach uses a compact, URL-safe means of representing claims to be transferred between two parties?
- OAuth 2.0
- JSON Web Tokens (JWT)
- SAML (Security Assertion Markup Language)
- OpenID Connect
JSON Web Tokens (JWT) is an authentication approach commonly used in ASP.NET Core Web APIs. JWTs are compact and URL-safe, making them efficient for transferring claims between parties. They provide a secure way to represent user identities and access permissions.
You're building a simple website using ASP.NET Core. You want to display a friendly error page when something goes wrong in your application. What's the standard way to do this in ASP.NET Core?
- Custom Error Page
- Detailed Logging
- Exception Handling Middleware
- Using Console.WriteLine()
The standard way to display a friendly error page in ASP.NET Core is by using Exception Handling Middleware. This middleware captures unhandled exceptions and can be configured to display custom error pages, making it easier for users to understand what went wrong.
In a project where user registration is done programmatically, you want to ensure that users have a strong password and are locked out after 5 incorrect login attempts. Which class should you configure to enforce these rules?
- IdentityUser
- IdentityRole
- PasswordHasher
- IdentityOptions
To enforce password strength rules and configure account lockout settings, you should configure the IdentityOptions class. This class allows you to set various security-related options, including password complexity requirements and account lockout thresholds.