Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Grab the RoutesConfig object from the HTTP configuration properties
object value;
config.Properties.TryGetValue("RoutesConfig", out value);
var routesConfig = value as RoutesConfig;
// Map each route from RoutesConfig
if (routesConfig != null)
{
foreach (var route in routesConfig.Routes)
{
var defaults = new
{
controller = route.Controller,
action = route.Action,
logging = route.Logging
};
var constraints = new
{
httpMethod = new HttpMethodConstraint(route.Method)
};
// Add the route to the Web API route table
config.Routes.MapHttpRoute(route.Name, route.Template, defaults, constraints);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment