How to add custom methods to ASP.NET WebAPI controller?

后端 未结 4 1406
悲&欢浪女
悲&欢浪女 2020-12-14 01:52

In ASP.NET MVC WebAPI project by default we have created following controller

 public class ValuesController : ApiController
    {
        /         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 02:20

    You can use attributes such as the RoutePrefix with the Http type.

    [Route("ChangePassword")]
    [HttpPost] // There are HttpGet, HttpPost, HttpPut, HttpDelete.
    public async Task ChangePassword(ChangePasswordModel model)
    {        
    }
    

    The http type will map it back to its correct method in combination with the Route name.

提交回复
热议问题