Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

HttpWebAttributeRoutingConfiguration does not seem support UriPathExtensionMapping #150

Closed
jasmeetsangari opened this Issue · 5 comments

2 participants

@jasmeetsangari

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

@mccalltd
Owner

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.

@jasmeetsangari

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

@mccalltd
Owner

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?....

@jasmeetsangari

That would work . Thanks..

@mccalltd mccalltd closed this
@mccalltd
Owner

Published to nuget: v3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.