public class AutomaticExtensionRouteProvider : DefaultDirectRouteProvider
{
protected override IReadOnlyList<RouteEntry> GetActionDirectRoutes(
HttpActionDescriptor actionDescriptor,
IReadOnlyList<IDirectRouteFactory> factories,
IInlineConstraintResolver constraintResolver)
{
var result = base.GetActionDirectRoutes(actionDescriptor, factories, constraintResolver);
var list = new List<RouteEntry>(result);
foreach(var route in result.Where(r => !r.Route.RouteTemplate.EndsWith(".{ext}")))
{
var newTemplate = route.Route.RouteTemplate + ".{ext}";
if (!result.Any(r => r.Route.RouteTemplate == newTemplate))
{
var entry = new RouteEntry(null, new HttpRoute(newTemplate,
new HttpRouteValueDictionary(route.Route.Defaults),
new HttpRouteValueDictionary(route.Route.Constraints),
new HttpRouteValueDictionary(route.Route.DataTokens)));
list.Add(entry);
}
}
return list.AsReadOnly();
}
}
jachguate
- 32.1k
- 8
- 41
- 69
No hay necesidad de poner gracias o cosas parecidas: http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/
Carlos Muñoz
- 13.5k
- 2
- 47
- 67