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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *