-1

I am trying to create a custom route for an API Controller, that has the following structure:

/{currentUrl}/{methodName}

currentUrl does not come as a parameter.

Example:

/tool/compute/download

where "download" is the name of the method, and "/tool/compute/" is the current page we are on.

Just to mention, I am using Sitecore.

Could anyone help?

Thanks.

Marius Popa
  • 564
  • 1
  • 5
  • 22

1 Answers1

1

You could build a method that takes the tool name as an agument, like this:

    [Route("tool/{toolName}/download")]
    public HttpResponseMessage Get(string toolName)
    {
        var path = GetPathByToolName(toolName);
        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
        var stream = new FileStream(path, FileMode.Open);
        result.Content = new StreamContent(stream);
        result.Content.Headers.ContentType =
            new MediaTypeHeaderValue("application/octet-stream");
        return result;
    }
Oliver
  • 1,225
  • 10
  • 19
  • The thing is that {currentUrl} it's generated through Sitecore. I need to take it as it is. Is that even possible? – Marius Popa Jun 12 '15 at 08:46
  • I don't know sitecore and I don't know if they got a solution for that. If not I would try to extend the routing at runtime. http://www.strathweb.com/2014/07/building-strongly-typed-route-provider-asp-net-web-api/ explains how to extend and plug in your own custom logic into the attribute routing engine. – Oliver Jun 12 '15 at 08:53