What is the primary purpose of the [Authorize] attribute in ASP.NET Core?
- Authentication
- Authorization
- Caching
- Logging
The [Authorize] attribute in ASP.NET Core is primarily used for Authorization, not Authentication. It restricts access to a particular action method or controller to only authenticated users who meet specific authorization requirements. This helps in controlling who can access different parts of your application based on roles or policies.
After a user logs into your application, you want to display a personalized greeting like "Welcome, [Username]!". How can you fetch the username of the currently logged-in user in ASP.NET Core?
- Use HttpContext.User.Identity.Name
- Query the database for the username
- Prompt the user to enter their username after login
- Use a hardcoded username
In ASP.NET Core, you can fetch the username of the currently logged-in user by accessing HttpContext.User.Identity.Name. This property contains the username of the authenticated user, allowing you to display a personalized greeting like "Welcome, [Username]!".
The [______] attribute in ASP.NET Core is used to specify the route template for an action method.
- Route
- HttpPost
- Authorize
- ValidateAntiForgeryToken
In ASP.NET Core, the [Route] attribute is used to define the route template for an action method. This template determines how the URL should be structured to access the method. For example, [Route("api/products")] specifies that the method should be reachable at the URL "api/products."
If you wish to apply a unique constraint on a column using the Fluent API in Entity Framework Core, which method should you use inside OnModelCreating?
- HasIndex
- HasUniqueConstraint
- IsUnique
- SetUnique
To apply a unique constraint on a column in Entity Framework Core using the Fluent API, you should use the IsUnique method. This method ensures that the database enforces uniqueness for the specified column or columns, preventing duplicate values from being inserted. It's a crucial feature for maintaining data integrity.
Which of the following tools is NOT typically used for ASP.NET Core development?
- Eclipse
- Rider
- Visual Studio
- Visual Studio Code
While Eclipse is a powerful IDE mostly known for Java development and other types of development, it's not typically used for ASP.NET Core development. Tools like Visual Studio, Visual Studio Code, and Rider provide integrated support for ASP.NET Core.
Your company's security policy dictates that users must change their passwords every 60 days. How would you implement this requirement using ASP.NET Core Identity?
- Implement a custom middleware
- Configure the Password Policy
- Use a third-party authentication library
- Manually reset passwords every 60 days
To enforce password change policies in ASP.NET Core Identity, you would configure the Password Policy settings. This includes setting options like PasswordExpiration, RequiredUniqueChars, and MinimumPasswordLength. By configuring these settings, you can enforce password changes every 60 days as per your company's security policy.
If you were looking to define custom scripts that should run during build or post-build events, where would you specify this in the project.json file?
- scripts section
- buildOptions section
- tools section
- dependencies section
In the project.json file, you would specify custom scripts that should run during build or post-build events in the "scripts" section. This section allowed developers to define pre-build, post-build, and other custom scripts for various project tasks.
The ________ template in ASP.NET Core ensures that JavaScript dependencies are managed using the Node package manager.
- Angular
- Blazor
- React
- SPA (Single Page Application)
The Blazor template in ASP.NET Core is designed for building web applications using C# and .NET. It ensures that JavaScript dependencies are managed using the Node package manager (npm) when necessary. This template provides a framework for building web applications that can run entirely on the client side or with server-side rendering, giving developers flexibility in their approach.
The asp-action attribute in a Razor form specifies the _________ to which the form will be submitted.
- Action Method
- URL
- Controller
- View
The asp-action attribute in a Razor form specifies the Action Method to which the form will be submitted. This attribute defines the method in the controller that will handle the form submission. It's an essential part of creating interactive web forms in ASP.NET Core.
You've been asked to implement email confirmation for new users. Which steps would be essential in implementing this feature using ASP.NET Core Identity?
- Configure Email Service, Update Startup.cs, Send Confirmation Link, Add ConfirmEmailAsync
- Update User Profile, Configure SMTP Server, Use SendGrid, Modify User Registration
- Use Third-Party Library, Configure Azure AD, Enable Cookies, Update NuGet Packages
- Create a New View, Implement CAPTCHA, Configure Anti-Forgery Tokens, Add OAuth Authentication
Implementing email confirmation in ASP.NET Core Identity involves several steps. You need to configure an email service, update the Startup.cs to include email settings, send a confirmation link to the user's email, and add a ConfirmEmailAsync method to confirm the email address when the link is clicked.
How does the "Worker Service" template in ASP.NET Core differ from the traditional web application templates?
- It focuses on client-side rendering.
- It's designed for background processing tasks without HTTP endpoints.
- It uses the Model-View-Controller (MVC) pattern.
- It has a built-in database.
The "Worker Service" template in ASP.NET Core is tailored for background processing tasks, such as scheduled jobs, message processing, and other non-HTTP tasks. It doesn't include the typical web application features like HTTP endpoints, controllers, or views, making it ideal for scenarios where you don't need to handle HTTP requests.
In the context of Razor, what were "Master Pages" used for in the older versions of ASP.NET?
- Defining a consistent layout for web pages
- Managing database connections
- Handling HTTP requests
- Creating server controls
In the context of older versions of ASP.NET, "Master Pages" were used to define a consistent layout for web pages. They allowed developers to create a template or master layout that contained the common structure and elements shared by multiple pages, similar to Razor Layout Views in ASP.NET Core. Master Pages helped maintain a uniform appearance across a website.