How to create dynamic routing in Orchard

Topics: Customizing Orchard, General
Jun 7, 2011 at 8:17 PM

This is frustratingly hard to explain, but we are going to be using Orchard for our site. What is unique about our site, and where my question comes in to play, is that my site allows for unique users to have their own unique "site". For example, if John registered with us he would have his own unique url, www.sitename.com/john. Not only this, but each user would then have all of the sites pages available to them, i.e. www.sitename.com/john/products for the product page. What is important though is that everything is routed according to their unique name and that all users have the same pages. The pages are just replicated across all users. Also, the users would be added on the fly as they register so the routes aren't something I could have hard coded in the global.asax. The list of users would be pulled from an existing database (or cache or whatever mechanisim - that part isn't important. Just the fact that the list will be constantly changing). There would be way too many users (thousands) to use the multi-tenant features built in to Orchard. My question is how would I accomplish this with Orchard and has anyone attempted anything like this?

Thank you!

Jun 8, 2011 at 11:07 AM

Actually I've been writing a new feature on my Mechanics module that could do this. The feature is called Plumbing and it provides a replacement routing system that can be configured in a variety of ways.

It's not quite production ready yet; the latest source code basically works, but there are a number of known issues.

Something to note about Orchard is that users are actually just stored as content items. My Plumbing feature then allows you to flexibly customise URL building for content items, and then have sub-URLs based on connections between content. The main feature of Mechanics is defining those connections. So with perhaps a bit of extra configuration and customisation you could definitely implement what you're describing. You just need to create a connector from the user to the content, each time the user creates something - this will probably be a standard feature eventually, but you could do it easily by hooking into the right events. Then finally you'd have those connectors control URL generation.

I think doing it otherwise by hand would be quite tricky and you'd end up having to reimplement a number of Orchard's core mechanisms if you still wanted your users to have all of the existing CMS features available. Whereas with the approach I've described, each time you added a new content type it would just be available to all the users without having to write any new routing code.

Jun 10, 2011 at 3:02 PM

Thanks for your reply Pete. One thing I may not have been clear on is that these are not Orchard users. To say they are users may not be the best wording - they are registered members of our company, unrelated to Orchard users. We track and maintain the members on our own system, which would be accessible to Orchard through a web service or direct database access.

Jun 10, 2011 at 4:17 PM

Well yes I got that - but the system I'm describing requires users to be repesented in the database as Content Items (which is Orchard's default user implementation). You could easily run a background service to automate synchronising Orchard's users with your service; and then you could take full advantage of other Orchard modules, like Profile. You actually lose out on a few things if you don't have the user-as-content model.

You can of course swap out Orchard's implementations of membership and roles and implement them based on your service instead; but a certain number of things would definitely be harder or unavailable if you did so.