user1593329
user1593329

Reputation: 51

Composite C1 routes.MapPageRoute - Directing to a page

I have been adding some custom routes which are not working

  1. I can get this MVC route working but the problem is it simple routes directly to the view rather than the page which contains the master layout etc. routes.MapRoute("Job-Listing", "job-detail/{category}/{title}/{id}", new { controller = "JobSearchModule", action = "JobDetail" });

  2. I tried routing to a page which existed like following. This didn't work and simple went to a page not found. routes.MapPageRoute("Job-Listing", "job-detail/{category}/{title}/{id}", "~/job-seekers/job-search/job-detail");

  3. I guessed that this might be because this is not a physical path and there is some other routing going off under the hood. So I tested this by adding a Route to a physical page like follows. (this route worked) routes.MapPageRoute("jobDetail2Route", "job-detail/{category}/{title}/{id}", "~/Text.aspx");

This got my thinking that composite c1 might have a physical URL which the C1 routing maps to. I'm sure I have seen at some point something to do with a /Renderers/Page.aspx. Does anyone know if I could somehow route to a physical page in this way?

Thanks

David

OK so some further information.

  1. I realized I could get the the URL using /Renderers/Page.aspx?pageId=d622ab3b-2d33-4330-9e6e-d94f1402bc80. This URL works fine so I attempted to add a new route to this URL like as follows...

routes.MapPageRoute("Job-Listing", "job-detail/{category}/{title}/{id}", "~/Renderers/Page.aspx?pageId=d622ab3b-2d33-4330-9e6e-d94f1402bc80");

Unfortunately this still didn't work. I got an error on the Renderers/Page.aspx Value cannot be null. Parameter name: pageUrlData

Any ideas?

Upvotes: 0

Views: 439

Answers (1)

mawtex
mawtex

Reputation: 436

Rather than using the internal representation of a page URL like ~/Renderers/Page.aspx?pageId=d622ab3b-2d33-4330-9e6e-d94f1402bc80 you should use the public representation like /my/page/url.

To get the public representation from the page id you could use a method like this:

using Composite.Data;
...
public string GetPageUrl( Guid pageId )
{
    using (var c = new DataConnection())
    {
        PageNode p = c.SitemapNavigator.GetPageNodeById(pageId);
        return p.Url;
    }
} 

This will give you the public URL of the page with the provided id. If you are running a website with different content languages this method will automatically fetch you the URL matching the language of the page your MVC Function is running on.

Should you have the need to explicitly change the language of this URL use the overload DataConnection(CultureInfo culture) instead of the default constructor.

With the above method in place you should be able to do this:

routes.MapPageRoute(
   "Job-Listing", 
   "job-detail/{category}/{title}/{id}", 
   GetPageUrl(Guid.Parse("d622ab3b-2d33-4330-9e6e-d94f1402bc80")); 

Upvotes: 1

Related Questions