HttpWebAttributeRoutingConfiguration does not seem support UriPathExtensionMapping #150

Closed
jasmeetsangari opened this Issue Nov 20, 2012 · 5 comments

Comments

Projects
None yet
2 participants

With MVC 4 you could add UriPathExtensions
config.Formatters.JsonFormatter.MediaTypeMappings.Add(new UriPathExtensionMapping("json", "application/json"));
config.Formatters.XmlFormatter.MediaTypeMappings.Add(new UriPathExtensionMapping("xml", "application/xml"));

and then when add the routes you can add extension as follows:

config.Routes.MapHttpRoute(
name: "ControllerWithExt",
routeTemplate: "api/{controller}.{ext}");
config.Routes.MapHttpRoute(
name: "IdWithExt",
routeTemplate: "api/{controller}/{id}.{ext}");
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

There does not seem to be easily supported by HttpWebAttributeRoutingConfiguration . Please Correct me if I am wrong

Owner

mccalltd commented Nov 20, 2012

See #140 for possibly relevant discussion.

You could write your own implementation of the AttributeRouteFactory (default impl here), and when creating the route, append the .{ext} to the end.

Thanks for the quick reply but the factory method CreateAttributeRoute returns one route but there has to be atleast two routes added to the routing table for each url (one with extension and one ithout extension )l...

        config.Routes.MapHttpRoute(
            name: "IdWithExt",
            routeTemplate: "api/{controller}/{id}.{ext}");
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }

Note the . between id and ext

Owner

mccalltd commented Nov 20, 2012

I could change the factory method so that it returns an enumerable of routes. That way you can send back more than one. Unless you have a better idea?....

That would work . Thanks..

@mccalltd mccalltd closed this Dec 4, 2012

Owner

mccalltd commented Dec 4, 2012

Published to nuget: v3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment