You are working on an ASP.NET Core MVC application, and a new requirement mandates that one of the action methods should only be accessible via HTTP POST. How would you implement this?
- Decorate the action method with [HttpPost] attribute
- Set the HTTP verb in the routing configuration
- Add a ValidateAntiForgeryToken attribute
- Use a custom middleware
To restrict an action method to only accept HTTP POST requests, you should decorate the action method with the [HttpPost] attribute. This attribute ensures that the method can only be invoked when an HTTP POST request is made to it.
Loading...
Related Quiz
- Besides the wwwroot folder, you can also specify custom _________ to determine from where the static files should be served.
- How do Razor Tag Helpers enhance the HTML markup in Razor views?
- You're setting up a new ASP.NET Core project, and you specifically need a template that provides user authentication out of the box. Which template should you select during the project setup?
- If you want to specify multiple roles for an action or a controller using the [Authorize] attribute, how would you do it?
- When you want to send a JSON response from your controller, which action result type should you utilize?