Sub-resources for friendly URLs

Topics: Writing modules
Oct 4, 2013 at 4:10 PM
I would like to create a module that allows users to create instances of a content type that exposes multiple sub-resources under a friendly URL. I am looking at using the Autoroute part for providing the base url and I would then like to hook up some additional views at paths under that URL. The goal is that if a user creates a page (that has my content type attached) with a friendly url like /my/content, I would like to be able to intercept and process requests to /my/content/subresource or /my/content/sub/sub/subresource with my own custom controllers (different controllers/actions for each of the different sub-resources).

I'm currently looking at the possibility of registering aliases for each sub-resource that map the friendly URL to my custom routes, but that seems a bit hacky and I wondered if there might be a more elegant way to do this.

Any suggestions would be most welcome!
Oct 4, 2013 at 8:44 PM
Then it's not Autoroute or aliases that you need, but plain old routing.
Oct 5, 2013 at 12:25 AM
Edited Oct 5, 2013 at 12:27 AM
Yes, but the easiest way would still be to create static aliases, I guess. At least if the subresources are known upfront.

Routing will get pretty tricky here as the default Route in ASP.NET does not allow the catch-all part anywere but at the end of the URL pattern, (ie. {bar*}/foo is not allowed but /foo/{bar*} is). Had a similar issue long time ago, and solved this using containers/containables and stub content items for (sub)resources to make use of the autoroute mechanism. If I would need to do this again, I'd create my own Route implementation, put all custom URL-matching logic in there and use this single route for intercepting resource requests and dispatching to proper controller/action. So yes - routing is the most elegant way but requires a bit more effort.
Marked as answer by techquila on 10/5/2013 at 4:15 AM
Oct 5, 2013 at 11:15 AM
Thanks @BetrandLeRoy and thanks too to @pszmyd for explaining my dilemma more accurately than I could. In my case I would ideally like parts of the subresource path to be dynamic. The problem is indeed that ordinary ASP.NET routing doesn't allow wildcards to proceed other parts of a URL pattern. I think I will go down the custom implementation route (pun intended).
Oct 5, 2013 at 9:58 PM
Oct 6, 2013 at 2:02 AM
But it still requires a custom implementation (as the answer there states). The default routing does not allow this.
Oct 6, 2013 at 4:41 AM
Not much. It's still the way to go.