Question

Since I updated my WebAPI 2 apps to WebAPI 2.1, routing stopped working. I had a couple of custom routing constraints implemented as GuidConstraint. The exception I was receiving was the following:

System.InvalidOperationException: The constraint entry 'guid' on the route with route template '{guid}/{language}/{controller}/{id}' must have a string value or be of a type which implements 'System.Web.Http.Routing.IHttpRouteConstraint'.

This problem is not mentioned in documentation.

The following post has a purpose of a knowledge sharing and opinion exchange.

Was my previous implementation wrong? What changes in the new implementation in 2.1 that doesn't anymore support the more generic interface?

Was it helpful?

Solution

The solution is to implement IHttpRouteConstraint instead of IRouteConstraint on your custom routing constraint classes. The logic in most of the cases will stay the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top