Route attributes do not register my controller method

I am trying to register a new route that handles the entry functions in the same way as for my other routes. Other routes worked, but only login does not.

Here is the route attribute for work routes :

 // POST api/user/adduser
 [HttpPost]
 [Route("api/user/adduser")]
 public IHttpActionResult AddUser([FromBody]User user) 
 {
     blah blah
 }

Here is my code for the Login method:

 // POST api/user/login
 [HttpPost]
 [Route("api/user/login")]
 public IHttpActionResult Login(String email, String password)
 {
     blah blah
 }

And finally, here is my WebApiConfig.cs:

 // Web API routes
 config.MapHttpAttributeRoutes();

 config.Routes.MapHttpRoute(
     name: "UserRouteApi",
     routeTemplate: "api/user/{method}"
 );

Here is what the http response is when I try to access login api ->

Output in browser:

Image

I do not understand, I created the route in the same way as before. Tried to restart visual studio, iis express, sure my route pattern is correct.

I need desperate help here!

+4
source share

Source: https://habr.com/ru/post/1649399/


All Articles