Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://msdn.microsoft.com/en-us/library/system.web.http.globalconfiguration%28v=vs.108%29.aspx" rel="nofollow">GlobalConfiguration</a> class can provide you access to the routing configuration.</p> <pre><code>// The code below assumes a map routing convention of api/{version}/{controller}/.... // This will give you the configured routes var routes = GlobalConfiguration.Configuration.Routes; // This will give you the route templates var templates = routes .Select(route =&gt; route.RouteTemplate); // This will give you the distinct versions for all controllers var versions = routes .Select(route =&gt; route.RouteTemplate) .Select(template =&gt; template.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) .Select(values =&gt; values[1]) .Distinct(); // This will give you the distinct versions for a controller with the specified name var name = "MyController"; var controllerVersions = routes .Select(route =&gt; route.RouteTemplate) .Select(template =&gt; template.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) .Where(values =&gt; String.Equals(values[2], name, StringComparison.OrdinalIgnoreCase)) .Select(values =&gt; values[1]) .Distinct(); </code></pre> <p>I am not sure if you are trying to resolve the version with a known value (the name of the controller) or if you are trying to dynamically resolve it. If you inject the current HttpContext, you can use the request URI of the context to filter the routes via the route template.</p> <p><strong>Edit:</strong> After your comments I realized the routing configuration isn't what you were after.</p> <p>If the end goal is to implement logging within your controllers, you may want to take a look at <a href="http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api" rel="nofollow">Tracing in ASP.NET Web API</a> as there is support for tracing built-in to the Web API infrastructure.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload