Friday, September 19, 2014

Web API 2 Attribute Routing - Error 500

I ran into a 500 Error last week while working on a project that uses Web API 2 for a REST like web service.  Looking up upon looking up error 500, I found that it was returned when there is more than one possible route for a request.  I went and looked at my convention based route definition which looked fine.  Then I paid a visit to the controller, where I found that I had two route attributes on my put and post methods that where defined as empty strings.  Whoops!


Lesson learned :) In Web API 2, if you mix route attributes with convention based routing, the route attribute takes precedent over the convention based route.  If a route attribute is not present, the default convention based route will be used. The route can't be duplicated!

No comments:

Post a Comment