Search code examples
c#asp.netroutesc1-cms

Dealing with generated pages in Composite C1


In my ASP.Net project which I am currently trying to move to Composite I have trouble with dealing with non-physical pages.

For the sake of simplicity, lets assume I have a webshop and each category in the database has its own url. (for example: /myshop/clothes)

In an ASP.NET project an url like this would be routed to a page Category.aspx that handles the request and reads the category content from the database.

Composite seems to be more focussed on "real" pages, what would be the best way to realize something like this? (especially the routing)

And: Is there a way to get these generated pages to work with modules like Navigation.Path for example?


Solution

  • For Menu generation and bread crumbs you would need to handle it yourself, eventually using the SiteMap.Resolve event on the SiteMapProvider to dynamically hook-in your "non-existing" pages.

    Regards to routes, there is a functionality in C1, that parses the url into the first "real page" and hands you the excess part of the url that you can work with. Lets say /myshop was your shop-page, and a user requested /myshop/clothes, then it would still be /myshow that would be executed, and you would put code in there that would handle your categories.

    The code that would extract "clothes" on your "myshop" page would be Composite.Core.Routing.Pages.C1PageRoute.GetPathInfo(), and to instruct C1 not to throw a 404 error, you call Composite.Core.Routing.Pages.C1PageRoute.RegisterPathInfoUsage(), to let C1 know that "clothes" was a valid category.

    Read more about the API for it here.

    If you need to handle different situations for when a category is selected, and when a user just hits /myshop directly, you would set the MyShop page to use a specific template, and in there you would wrap the <rendering:contentplaceholder> element in a function that has some kind of else-if logic. If no category is selected, print out the content of <rendering:contentplaceholder>, otherwise do some lookups based on the category and print out some other content instead.