Take the 2-minute tour ×

I'm building a MVC 4.0 WEB API app, and want to use the following route:


I want to use the appId parameter and use it to set a value in the HttpContext.Current.Items collection, and want it out of the Action matching process. I certainly do not want to add a appId parameter to each and every action method in my controllers.

Does anyone have an idea how to achieve that?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
  1. You don't need to include appId as a parameter; web API will route to the action that matches the best subset of route parameters. So if no actions have an appId parameter, it will just match on id1, id2, and action name (from {action}).

  2. If you want to get the value of appId inside the controller action, you can get the route values from the ControllerContext.RouteData.Values dictionary. (Not sure if that's you're scenario. Do you specifically need to store it in HttpContext.Current.Items?)

This article describes action selection in some detail: http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection

share|improve this answer
Thank you, Mike! –  nir.arazi Sep 16 '12 at 9:40
add comment

Your Answer


