How to Restrict Access to Web API Method to Specific HTTP Verb?

Technology CommunityCategory: ASP.NET Web APIHow to Restrict Access to Web API Method to Specific HTTP Verb?
VietMX Staff asked 3 years ago

Attribute programming plays its role here. We can easily restrict access to an ASP.NET Web API method to be called using a specific HTTP method. For example, we may require in a scenario to restrict access to a Web API method through HTTP POST only as follows:

[HttpPost]
public void UpdateStudent(Student aStudent)
{
      StudentRepository.AddStudent(aStudent);
}