My simple web api application keeps returning "500 Internal Server Error" with the message "Multiple actions were found that match the request" and I thought this must be a routing problem.
Here is a gist with the UserController and the WebApiConfig files that can have an impact on this issue.
I went with the web api convention when I created my methods and I don't want to use attributes on the methods to specify type and route.
If I use a Route attribute on the POST method, it will work, but it doesn't make sense to me why it doesn't work w/o that attribute since I use the naming convention for a POST method.
ex that works:
[Route("api/user")]
public IHttpActionResult Post([FromBody]User user)
{
if (!ModelState.IsValid)
{
return BadRequest("Model state not valid!");
}
if (db.Users.ToList().Any(u => u.Username.ToLowerInvariant().Equals(user.Username.ToLowerInvariant())))
{
return BadRequest("Username already exists in the database!");
}
db.Users.Add(user);
db.SaveChanges();
return Ok($"Added user {user.Username}");
}
Any thought is welcomed.