Attribute Routing changes for ASP.NET Web Stack shipped in VS2013 RC

Attribute Routing changes for ASP.NET Web Stack shipped in VS2013 RC

  • Comments 4

For the VS2013 Preview release, we published two articles about Attribute Routing for Web API 2:

· http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

· http://www.asp.net/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing

The VS2013 RC release includes more changes and features for attribute routing:

1. Explicitly declare a route template on an action

In RC, if attribute routing is enabled, you must explicitly declare the attribute for the desired actions. In Preview, you don’t have to.

clip_image001

2. Added support for overriding RoutePrefix attribute.

In the following controller code, the action to ‘get all the books’ has a route template like “~/”. This overrides the RoutePrefix for this action and a user can reach this action by requesting GET on http://hostname:hostport/ .

clip_image002

3. Support for multiple RoutePrefix attributes on a controller has been removed. Only one RoutePrefix attribute can be applied to a controller.

4. The Order property is removed from the RoutePrefix attribute.

We’ll be changing even more for RTM -- stay tuned. For information about what’s planned, see the attribute routing design specification on the CodePlex site.

Leave a Comment
  • Please add 8 and 1 and type the answer here:
  • Post
  • Why has support for multiple RoutePrefix attributes been dropped?? It was quite useful for implementing Api versioning scenarios where you have RoutePrefix("/api/v2/people") and RoutePrefix("/api/people") basically for having an "edge" version that always points to the latest version.

  • Thanks for all the enhancements.

    For One ASP.net, can you guys please implement an option to select from multiple layout frameworks besides Twitter Bootstrap? One of the most popular is Zurb Foundation. It would be great if we have choice to select from these popular layout frameworks (HTML5Boilerplate, Zurb Foundation, Bootstrap) when creating new ASP.NET project.

    I have posted the suggestion on uservoice aspnet.uservoice.com/.../4449961-zurb-foundation-as-a-template-option-when-creatin

    Please vote it up if you like the idea.

    Thanks

  • Thanks for all the enhancements.

    For One ASP.net, can you guys please implement an option to select from multiple layout frameworks besides Twitter Bootstrap? One of the most popular is Zurb Foundation. It would be great if we have choice to select from these popular layout frameworks (HTML5Boilerplate, Zurb Foundation, Bootstrap) when creating new ASP.NET project.

    I have posted the suggestion on aspnet.uservoice.com/.../4449961-zurb-foundation-as-a-template-option-when-creatin

    Please vote it up if you like the idea.

    Thanks

  • @Juri:

    Having multiple route prefixes causes issues when you have an explicit route name for a particular action (Ex: "GetOrderById" route name on a Get(id) action). As you can imagine in this case if there are multiple route prefixes then mutliple routes would be having the same route name which is incorrect.

    NOTE: Here I am using post-RC example code.

    Following are some workarounds that you could use for your scenario:

    a. Define multiple routes on each of the actions of the controller.

    b. Define multiple 'RouteAttribute' on the controller. In the following example 'Get' action can be reached by both the routes defined on the controller.

       [Route("api/values-route1")]

       [Route("api/values-route2")]

       public class ValuesController : ApiController

       {

           // GET api/values

           public IEnumerable<string> Get()

           {

               return new string[] { "value1", "value2" };

           }

       }

    You can learn more about post-RC attribute routing changes over here:

    aspnetwebstack.codeplex.com/wikipage

Page 1 of 1 (4 items)