Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Web API 2 Service - how to set constraints on parameters in WebApiConfig

$
0
0

So I have set up the following route in my WebApiConfig file. It works fine if I take out the line with the constraints.
It also fails if I simply the constraints line to: constraints:=New With {Key .age = "int"}
When I run the code in my local debugger in VS2015 I am getting a 403 error.

So how do I properly define constraints in VB.NET?

 ' Web API routes
        config.Routes.MapHttpRoute(
            name:="GetMyData",
            routeTemplate:="api/{controller}/{age}/{state}/{country}",
            defaults:=New With {Key .age = "999", Key .state = "MissingState", Key .country = "MissingCountry"},
            constraints:=New With {Key .age = "int:range(0,125)"}
        )


Viewing all articles
Browse latest Browse all 4850

Trending Articles