title: .NET Web API Slash in Route
body: <p>I have a .NET Web API v2 and need to define a route that can contain forward slashes at any point in the route. I have it configured (something) like this in WebApiConfig:</p>
  
  <pre><code>config.Routes.MapHttpRoute(
      name: "SomeRouteName",
      routeTemplate: "api/summary/{*token}",
      defaults: new { controller = "Summary" });
  </code></pre>
  
  <p>Unfortunately the token contains slashes and there's nothing I can do about it at this point. The above route works in most cases if the slash is not at the beginning of the token. So that takes care of most cases. But if token begins with slash(es), it doesn't work because that first slash gets interpreted as part of the URL I assume and gets eaten. So in my controller action, I have the following code (admittedly a hack that I'm trying to avoid):</p>
  
  <pre><code>if (summary == null)
  {
      summary = _repo.GetSummary($"/{token}");
  }
  </code></pre>
  
  <p>Obviously, this will only work for a single slash. I could do a loop and add more, but there isn't way to know how many it could be. Currently no tokens in my DB begin with two slashes, so this bad code works for now. It was implemented as a band-aid until a better solution is found.</p>
  
  <p>Edit: This references the * route, which mostly fixed my original issue, but still doesn't match the first slashes: <a href="https://stackoverflow.com/questions/6328713/urls-with-slash-in-parameter">URLs with slash in parameter?</a></p>